扫描字符串并用C语言打印
我能做些什么呢扫描字符串并用C语言打印,c,string,printf,scanf,C,String,Printf,Scanf,我能做些什么呢 #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':
#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);
}
#包括
#包括
void lee(char s[]);
无效描述(chars[]);
int main()
{
char-str[20];
char ch;
printf(“1描述\n2李”);
ch=getchar();
开关(ch){
案例“1”:
printf(“您在描述(写入)\n”);
李(str);
打破
案例“2”:
printf(“您在李(读)\n”);
描述(str);
打破
违约:卖出(“错误”);
}
返回0;
}
void lee(char s[]){
printf(“写下你的句子”\n);
scanf(“%[^\n]”,s);
}
无效描述(字符s[]){
printf(“输入的字符串是%s\n”,s);
}
我并不是说这是好代码,但我“认为”这正是您要做的。
也许它会给你一个想法,这样你就可以按照你想要的方式修改你的代码
#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");
}
#包括
#包括
#包括
void lee(char s[]);
无效描述(chars[]);
int main()
{
char str[20]={0};
char ch='\0';
而(1)
{
printf(“\n1描述:\n2李:\n”);
ch=getchar();
fseek(stdin,0,0);
开关(ch){
案例“1”:
printf(“\n您在描述(写入)\n\n”);
李(str);
打破
案例“2”:
printf(“\n您在李(读)\n\n”);
描述(str);
打破
违约:卖出(“错误”);
出口(1);
}
}
返回0;
}
void lee(char s[]){
printf(“写下你的句子:\n”);
scanf(“%19[^\n]”,s);
fseek(标准差,0,0);
printf(“\n”);
}
无效描述(字符s[]){
printf(“输入的字符串为:%s”,s);
printf(“\n”);
}
定义“不工作”。会发生什么?该怎么办?当我去找李的时候,我不能写,也不能在你的问题上加上各种恐慌的“帮帮我”文字。相反,停下来,深呼吸,更详细地解释问题所在。printf说了一件事,调用的方法在错误的地方。包括清晰的描述你想要的结果。