c语言输入多组字符串
❶ c语言中用scanf连续输入多个字符串的数据会重复为什么
问题出在以下定义:
char name[6];
char number[18];
char phone[11];
char year[4];
char month[2];
char day[2];
字符数组name只能存储长度为5的字符串,因为结尾还有一个\0,而你的输入已经越界了,后面输入的内容将前面的\0覆盖,导致字符串输出异常,其他5个情况类似。
❷ c语言中怎么连续输入几个字符串
1、首先我们新建一个dev C++的项目。
❸ C语言如何一次输入多个字符串,然后再输出
1、首先打开visual studio软件,新建一个C语言文件。
❹ C语言中如何输入多组带空格的字符串;关键是多组,单组的话我会的。
你是要实现首字母变大写吧,我这个AC了,你看看
#include<stdio.h>
#include<string.h>
int main()
{
int i,l;
char a[100] ;
while (gets(a)!=NULL)
{
l=strlen(a);
a[0]=a[0]-32;
for (i=1;i<l;i++)
if (a[i-1]==' ')
a[i]=a[i]-32;
puts(a);
}
return 0;
}
while中的意思是只要输入的值不为空,他就能一直输入
❺ C语言函数scanf_s能不能输入多个字符串
void main(){
char s[10],ss[10];
scanf_s("%[^复,],%s",s,10,ss,10);
printf("%s %s",s,ss);
}
因为你制需要输入逗号,所以对逗号应该特别处理.
❻ C语言如何实现输入多组数字字符串
用一个特殊字符标识就可以了嘛
❼ C语言中如何输入多行字符串
#include<stdio.h>
voidmain(){chars[81];inti,j,n;
for(i=0;i<3;i++){
gets(s);j=0;n=0;
while(s[j]!=0){
if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u'
||s[j]=='A'||s[j]=='E'||s[j]=='I'||s[j]=='O'||s[j]=='U')
n++;
j++;
}
}
printf("%d ",n);
}
❽ c语言如何输入多组字符串
输入任意多组字符串不好用二维数组,因为数组大小不好定义,可以用动态分配内存来实现。
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
main()
{
char **p=NULL,
**temp=NULL,
*str=NULL,
*s=NULL;
int a=0,b=0,c=5,i=0,j=0;
for(;;)
{
if(a==b)
{
b+=2;
temp=(char**)malloc(b*sizeof(char*));
if(p)
{
for(i=0;i<a;i++)
*(temp+i)=*(p+i);
free(p);
}
p=temp;
temp=NULL;
}
str=(char*)malloc(c);
i=0;
while((*(str+i++)=getchar())!='\n')
if(i==c)
{
c+=2;
s=(char*)malloc(c);
for(j=0;j<i;j++)
*(s+j)=*(str+j);
free(str);
str=s;
s=NULL;
}
if(i<2)
break;
*(str+i-1)='\0';
*(p+a)=(char*)malloc(strlen(str)+1);
strcpy(*(p+a++),str);
free(str);
str=NULL;
}
for(i=0;i<a;i++)
{
printf("%s\n",*(p+i));
free(*(p+i));
}
free(p);
}
❾ c语言怎么输入多个字符串
char
str1[20],str2[20];
scanf("%s%s",str1,str2);
这样就可以实现多个字符串的输入,注意几点:
1.
输入的每一个字符串长度应小于定义时的字符数组长度。
2.
输入字符串时,字符串与字符串之间用空格符或者回车换行符隔开。
❿ 如何输入多组含字符串和数字的字串
楼主您好!如果是需要单独处理一行里的每个元素的话,除了一次读一行来strtok之外,还可以像这样:
#include
#include
int
main()
{
int
count;
char
buffer[256];
scanf("%d",
&count);
while
(count--)
{
do
{
scanf("%s",
buffer);
//
这里判断一下buffer里的内容是字符串还是数字串再分别处理就好,如果数字的个数确定的话就更好办了。
//
处理完毕后,就可以按需使用读到的内容了,希望能解决您的问题^_^
}
while
(getchar()
!=
'\n');
}
return
0;
}