NPPExec scanf Notepad++ Console

453 Views Asked by At

im new to NPPExec and c coding. Is there a way to compile and run a c code like

int number;
scanf("enter a number: %d" ,&number);
printf("\nyour number is: %d\n", number);

when i try

NPP_SAVE cd $(CURRENT_DIRECTORY) cmd /c g++ -utf-8 -pedantic -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings $(FILE_NAME) -o $(NAME_PART).exe& IF ERRORLEVEL 1 (echo. && echo Syntax errors were found during compiling.) ELSE ( cmd /c "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" -run)

the scanf() is ignored

Please help :/

1

There are 1 best solutions below

0
On BEST ANSWER

in

int number;
scanf("enter a number: %d" ,&number);
printf("\nyour number is: %d\n", number);

It looks as though you are attempting to print out a user prompt in the call to scanf. Unfortunately that's not what scanf does.

You need to print out the prompt separately. Give

int number;
prinf("enter a number: ");
int rval = scanf("%d", &number);
if (rval == 1) // test that read got something
{
    printf("\nyour number is: %d\n", number);
}
else
{
    printf("\nyour input is USELESS!\n", number); // though a less mocking tone 
                                                  // is usually appreciated by users.
}

or something similar a shot.