Reputation: 55
int studentId,nOfWorkingDay;
char name[30],surname[30];
printf("Enter person information : name , surname ,studentId, nOfWorkingDay\n");
scanf("%s %s %d %d",&name,&surname,&studentId,&nOfWorkingDay);
printf("%s %s %d %d",name,surname,studentId,nOfWorkingDay);
I get a strange output. For example, when I enter:
birol genç 30 35
the output is:
birol gen┼ 30 35
What is the problem here?
Upvotes: 0
Views: 90
Reputation:
int studentId,nOfWorkingDay;
char name[30],surname[30];
printf("Enter person information : name , surname ,studentId,nOfWorkingDay\n");
scanf("%s %s %d %d",name,surname,&studentId,&nOfWorkingDay);
printf("%s %s %d %d",name,surname,studentId,nOfWorkingDay);
Upvotes: 1
Reputation: 1208
#include <stdio.h>
int main(){
int studentId,nOfWorkingDay;
char name[30],surname[30];
printf("Enter person information : name , surname ,studentId,nOfWorkingDay\n");
scanf("%s %s %d %d",name,surname,&studentId,&nOfWorkingDay);
printf("%s %s %d %d",name,surname,studentId,nOfWorkingDay);
}
description:
scanf("%s",firstname);
The %s placeholder is used to read in text, but only until the first white space character is encountered. So a space or a tab or the Enter key terminates the string. (That sucks.) Also, firstname is a char array, so it doesn’t need the & operator in the scanf() function.
Upvotes: 0
Reputation: 17668
scanf("%s %s %d %d",&name,&surname,&studentId,&nOfWorkingDay);
should be
scanf("%s %s %d %d", name, surname,&studentId,&nOfWorkingDay);
ie, remove the &
before name
and surname
which are already addresses of the character strings.
Upvotes: 2