|
#include<stdio.h>
char *read(char *p,int n);
int main(void)
{
char s[10];
char *p;
int q;
p=read(s,10);
return 0;
}
char *read(char *p,int n)
{
int m=n;
while(n--)
{p[m-n]=getchar();
printf ("%c",p[m-n]);}//print 1
printf ("\n");
puts(p);//print 2
return p;
}
For such a function, there is no problem with printing 1 sentence, why is there a problem with puts(), and it displays garbled characters? Does puts() must be used with gets()? |
|