Using strings with scanf problem

I'm trying to use the scanf function to assign a user inputted string to a variable called run.

Here's my int main() as that's where the problem lies:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(){
	int size;
    char run[4]="yes";  
	while (!strcmp(run,"yes")){ //allows the program to run while the variable 'run' is equal to yes (Found this function on www.cplusplus.com)
		printf("How many test scores do you want to enter? (Maximum of 30) ");
		scanf("%d",&size); //assigns the value entered as the variable 'size'
		if(size<2 || size>30){ //Checks if the number of test scores is not between 2 and 30 then the program doesn't run as it would error 
			printf("The number of test scores must be at least 2 but not exceed 30."); //error message
		} else { //runs main program
			enter_values(size); //runs the function 'enter_values'
			printf("\n--------Statistics--------\n");
			printf("The mean is %1.2f\n",mean(size)); //calls the mean function to work out the mean
			printf("The maximum value is %1.2f\n",maximum_value(size));
			printf("The minimum value is %1.2f\n",minimum_value(size));
			printf("The standard deviation is %1.2f\n",stddev(size));
		}
		printf("\n\nDo you want to run the program again? (yes/no)"); //asks the user if they want to run the program again
		scanf("%s",&run);//assigns their answer to 'run'
	}
}


The program works but I get a warning saying "warning 511 - Character pointer expected to satisfy %s format"

Just wondering why and how I can fix it? Thanks!
line 18: scanf("%s",&run);

if you remember your arrays, array_name is not the same as &array_name*

*assuming of course array_name was declared as an array :)
Last edited on
run is already a pointer (the name of an array converts to a pointer to its first element). Remove the ampersand.

Notice your code is very unsafe. What if the user types in more than 3 characters? You can determine the size of the input you want by saying this instead:

scanf("%3s", run);
Last edited on
Topic archived. No new replies allowed.