Previous: 11.5 Summary
Up: 11 String Processing
Next: 11.7 Problems
Previous Page: 11.5 Summary
Next Page: 11.7 Problems
What does each of the following print? Show each character.
printf("%s", s);
puts(s);
fputs(s, stdout);
string of characters\n
What does each of the following read? Show each character, including NULL.
scanf("%s", s);
gets(s);
fgets(s, sizeof(s) - 1, stdin);
s
*s
!*s
gets(s)
*gets(s)
!*gets(s)
Find and correct any errors in the following and determine the outputs where feasible. The input is shown when appropriate.
main()
{ char s[80], t[80];
s = "this is a message";
if (s == t)
printf("Equal\n");
else
printf("Not equal\n");
puts(s);
}
main()
{ char s[80], t[80];
scanf("%s", s);
printf("%s", s);
}
Input: This is a message
main()
{ char *s;
s = "this is a message";
printf("%d %s\n", s, s);
puts(s);
}
main()
{ char *s;
gets(s);
puts(s);
}
main()
{ char s[80];
while (*s) {
putchar(*s);
s++;
}
}
main()
{ char *s;
strcpy(s, "hello");
puts(s);
}
main()
{ char name[80];
name = get_str(name);
puts(s);
}
char *get_str(char *s)
{
gets(s);
return s;
}
int cmpstr(char *s, char *t)
{
if (s == t)
return TRUE;
else
return FALSE;
}