| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
#include<stdio.h> 
 
main() 
{ 
        char str1[20]; 
        char str2[20]; 
        char ch = NULL; 
        char ch1 = NULL; 
        int m = 0; 
         
        printf("Enter the first string:"); 
        ch = getchar(); 
        while((ch=getchar())!='\n') 
       { 
                str1[m] = ch; 
                m++; 
            } 
        str1[m] = '\0'; 
        m = 0; 
         
        printf("Enter the second string:"); 
        ch1 = getchar(); 
        while((ch1=getchar())!='\n') 
            { 
                str2[m] = ch1; 
                m++; 
            } 
        str2[m] = '\0'; 
        m = 0; 
         
        printf("The first string is %s.\n",str1); 
        printf("The second string is %s.\n",str2); 
} 
 
程序可以运行,但这里输入的两个字符串中第一个输入的字符都被忽略了,求解决....
- #include<stdio.h>
 
  
- main()
 
 - {
 
 -         char str1[20];
 
 -         char str2[20];
 
 -         char ch = NULL;
 
 -         char ch1 = NULL;
 
 -         int m = 0;
 
 -        
 
 -         printf("Enter the first string:");
 
 -         //这是你输入的第一个字符,在循环外面,自然被忽略了。
 
 -         ch = getchar();
 
 -         while((ch=getchar())!='\n')
 
 -        {
 
 -                 str1[m] = ch;
 
 -                 m++;
 
 -             }
 
 -         str1[m] = '\0';
 
 -         m = 0;
 
 -        
 
 -         printf("Enter the second string:");
 
 -         //这是你输入的第一个字符,在循环外面,自然被忽略了。
 
 -         ch1 = getchar();
 
 -         while((ch1=getchar())!='\n')
 
 -             {
 
 -                 str2[m] = ch1;
 
 -                 m++;
 
 -             }
 
 -         str2[m] = '\0';
 
 -         m = 0;
 
 -        
 
 -         printf("The first string is %s.\n",str1);
 
 -         printf("The second string is %s.\n",str2);
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |