【问题标题】:print from user to screen with (enter)使用(输入)从用户打印到屏幕
【发布时间】:2015-05-17 19:39:27
【问题描述】:

我是从用户打印字符串到屏幕的托盘当用户插入(输入)键时我遇到的问题程序转到新行并且用户仍然可以在屏幕上打印,但是当我插入时(输入)程序转到第一行并覆盖旧单词这是我的代码

#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
int len;
char searsh_word[10];
char ch;
    printf("enter your strings\n");
while(ch!='EOF'){
    ch=getch();
    printf("%c",ch);
   }
puts("\nEnter the word you need to search for : ");
scanf("%s",searsh_word);
len=strlen(searsh_word);
printf("your word length is : %d",len);


return 0;
}

【问题讨论】:

    标签: printing output


    【解决方案1】:

    问题是通过使用 getch() 你可以使用 grtchar() 以获得更好的结果

    #include <stdio.h>
    #include <stdlib.h>
    #include<string.h>
    FILE *file;
    int main()
    {
    int len;
    char searsh_word[10];
    char ch;
    file=fopen("test.txt","w");
    if(!file){
            printf("Error opening file\n");
            exit(1);
    }else{
        printf("enter your strings\n");
        }
        do{
        ch=getchar();
        fprintf(file,"%c",ch);
       }while(ch!='.');
       fclose(file);
    puts("\nEnter the word you need to search for : ");
    scanf("%s",searsh_word);
    len=strlen(searsh_word);
    printf("your word length is : %d",len);
    
    
    return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-06-15
      • 1970-01-01
      • 2021-12-23
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多