c中的gets 与scanf到底有什么差 ,如何实现键盘输入及屏幕显示

#if(0)
#include <stdio.h>
int main(int argc, char *argv[])
{
      //char *gets( char *str );
    char *str;    
    printf("plz input array:");
   //str= gets(str); 
   //scanf("%s",str) ;  
    printf("%s\n",str);    
    return 0;
}
#endif


#if(0)
#include <stdio.h>

int main()
{
    char *s;
    printf("please enter a word:\n");
    scanf("%s",s);
    printf("input word is:%s\n",s);
    return 0;
}
#endif


/*
differences:
1  gets() & scanf 

*/

#if(0)

    #include <stdio.h>
    int main()
    {
 char ch1, ch2;
 scanf("%c", &ch1);
 scanf("%c", &ch2);
 printf("%d  %d\n", ch1, ch2);
 return 0;
    }
    
    /*
    1. 
    k f
107  32
请按任意键继续. . .


2.
ab
97  98
请按任意键继续. . .

3.
 adkjaf
32  97
请按任意键继续. . .


4.
a enter 
97  10
请按任意键继续. . .

    
    
    */ 
#endif

#if(0)
 #include <stdio.h>
    int main()
    {
 char ch1, ch2;
 ch1 = getchar();
 ch2 = getchar();
 printf("%d  %d\n", ch1, ch2);
 return 0;
 
 /*
 1、 
 abcdskafjsaf
97  98
请按任意键继续. . .

2、
 a b
97  32
请按任意键继续. . .


 
 */
    }
#endif

#if(0)
    #include <stdio.h>
    int main()
    {
 char str1[20], str2[20];
 scanf("%s",str1);
 printf("%s\n",str1);   
 scanf("%s",str2); 
 printf("%s\n",str2); 
 return 0;
    }

/*

1\ 
hello world
hello
world
请按任意键继续. . .

2\
hello
hello
world
world
请按任意键继续. . .


*/
#endif 

#if(0)

#include <stdio.h>
int main()
{
 char str1[20], str2[20];
 gets(str1);
 printf("%s\n",str1);   
 gets(str2); 
 printf("%s\n",str2); 
 return 0;
 
 /*
 hello world
 hello world
 skdjfksajf
 skdjfksajf
请按任意键继续. . .

 
 */
}
#endif

#if(1)

    #include<stdio.h>  
    int main()  
    {  
        int a,i=1;  
        char c[100];  
        while(scanf("%d%s",&a,c)!=EOF)  
            printf("NO.%d:%d-%s-\n",i++,a,c);  
        return 0;  
    }  
    #endif
    
原文地址:https://www.cnblogs.com/yoyov5123/p/2934163.html