scanf problem

Hello!

When I am trying to compile, it says that it is done but when I try to run the program it says that it is not compiled. I tried to track down the problem. From what I was seeing, it turns out that the problem is with the scanf. I tried using it with and without ampersand but it doesn't work.

Here is a sample of the code:

#include<stdio.h>
#include<stdlib.h>

int main()

{
char p1[10], p2[10], ........ ;

printf("Welcome!\n");
printf("Enter R for Rock, S for Scissors, and P for Paper\n");
printf("\n");

printf("Please enter the name for player 1: ");
scanf("%9s", &p1);

printf("Please enter the name for player 2: ");
scanf("%9s", &p2);

........

system("PAUSE");

return(0);

}

I am using the latest version of Orwell on Windows 8.1.
P.S. I still new to programming :p
Any help? Thanks!
Last edited on
scanf("%9s", p1);

Good job on being aware of array overflow issues! Just... don't skimp on name length. Give those names more space, like 50 or 100 characters. And if you really want to be careful about inputs, make sure to synchronize by ignoring anything extra the user typed before pressing Enter:

while (getchar() != '\n') { }

Hope this helps.
Thanks for the tip! Anyways, do you think that orwell has a problem with win 8.1? I still can't compile the script if the scanf is still in the code :(
I can't imagine why. Are you sure you are compiling a C application and not a C++ one?
Yes I'm sure. I'll try to use code blocks if it will work.

Edit: Ok it works on code blocks. Dev c is really the problem lol
Last edited on
Topic archived. No new replies allowed.