What I can do to do this?
#include <stdio.h>
#include <string.h>
void lee(char s[]);
void escribe(char s[]);
int main()
{
char str[20];
char ch;
printf("1 escribe\n2 lee\n");
ch=getchar();
switch(ch) {
case '1':
printf("you are in escribe (write)\n");
lee(str);
break;
case '2':
printf("you are in lee (read)\n");
escribe(str);
break;
default: puts("Error");
}
return 0;
}
void lee(char s[]){
printf("write your sentense\n");
scanf("%[^\n]", s);
}
void escribe(char s[]){
printf("Entered string is %s \n", s);
}
I am not saying this is good code, but I "think" this is kind of what you are trying to do. Maybe it will give you an idea so you can fix your code the way you want it.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void lee(char s[]);
void escribe(char s[]);
int main()
{
char str[20] = {0};
char ch = '\0';
while(1)
{
printf("\n1 escribe:\n2 lee:\n");
ch = getchar();
fseek(stdin, 0, 0);
switch(ch) {
case '1' :
printf("\nYou are in escribe (write)\n\n");
lee(str);
break;
case '2' :
printf("\nYou are in lee (read)\n\n");
escribe(str);
break;
default: puts("Error");
exit(1);
}
}
return 0;
}
void lee(char s[]){
printf("Write your sentence: \n");
scanf("%19[^\n]", s);
fseek(stdin, 0,0);
printf("\n");
}
void escribe(char s[]){
printf("The entered string is: %s ", s);
printf("\n");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.