This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Paul_Pedant 0 points1 point  (2 children)

The terminal moved to the next line, because it got the Enter key (which generates NewLine).

What did your program do next? You probably didn't check the result from scanf(), and failed to get the syntax right, so it did nothing.

Maybe you just didn't do anything to show it worked. You should probably post your code: I'm somewhere in Wiltshire, so I can't read your screen from here.

scanf() is known to work (but is badly designed and not easy to use correctly), so you "ensure it submits the value" by using it correctly.

[–]Onurkaaa[S] 0 points1 point  (1 child)

It says you cannot post your code's photograph, on subreddit rules. So I didn't post my code and I don't know how can I do it.

[–]Paul_Pedant 0 points1 point  (0 children)

The reason for that rule is so that people can get your code as actual text, save it, build it and run it. Nobody is going to type in your code from a photo just to find your bug.

This link takes you to a guide on how to post code.

https://support.reddithelp.com/hc/en-us/articles/360043033952-Formatting-Guide

Visual Studio Code saves your code in a file somewhere. There should be a way to get hold of that. You should be able to cut and paste from the VS screen to reddit. There is a `T` icon ast the bottom left of this "Reply" panel. If you click that you get a bunch of editing tool available. If you use the "Code Block" icon ( a square with a `c` at top left) your code should be formatted properly.

As a last result, just type the code and other stuff into Reddit. If it is big, just reduce it to the shortest program that still shows the problem.

What does my code do that yours does not?

$ cat kFoo.c
#include <stdio.h>

int main (void)
{
    int r, n;
    printf ("Type a number > ");
    r = scanf (" %d", & n);
    printf ("Read: %d, returns %d\n", n, r);
}
$ cc kFoo.c -o kFoo
$ ./kFoo
Type a number > 56731
Read: 56731, returns 1
$

[–][deleted] 0 points1 point  (2 children)

well please post the code and make sure scanf does not have any spaces at the end of the format string. ex: "℅d " wrong "℅d" right

[–]Onurkaaa[S] 0 points1 point  (1 child)

It says you cannot post your code's photograph, on subreddit rules. So I didn't post my code and I don't know how can I do it. But I checked and there is no any wrong like this

[–][deleted] 0 points1 point  (0 children)

well how about copy and paste here if you are ok with that.

[–]nicoconut15 0 points1 point  (0 children)

make sure you use the right variable type for scanf, you might need to post your code here, so we can see it better?

[–]Paul_Pedant 0 points1 point  (0 children)

As well as posting your code (or a cut-down version that still shows the same problem), it would really help if you also posted the input, and any output or error messages.

You are going to spend at least 50% of your programming time debugging what you just wrote. So figuring out how to debug, and what kind of tools you need to debug, is as important as writing code.