Tag: 获取

字符串,获取和做

我正在用C做练习,但是我有一个问题,当我想重复cicle(做的时候),事实上,如果我输入1,程序再次由顶部开始,但它不会停止在gets(testo); 。 在没有解决方案的情况下,我尝试了很多方法来解决错误,有人可以帮助我吗? #include #include #include main(){ int cch, cw, i, j, w, ord, f; //counter and index char testo[80]; char alfa[50][25]; char swap[25]; do{ cch=0; cw=0; j=0; w=0; f=0; for(i=0;i<80;i++){ testo[i]='\0'; } printf("Write the text:\n"); gets(testo); //initialization 2d array for(i=0;i<50;i++){ for(j=0;j<25;j++){ alfa[i][j]='\0'; } } j=0; //Count word and characters if(testo[0]!='\0'){ cw=1; for(i=0;testo[i]!='\0';i++){ cch++; if(testo[i]==' […]

C动态中的字符数组是?

我在C中编写了一个简单的程序。一个程序输入一个String并显示它和长度。 #include int main() { char a[4]; printf(“Enter the name : “); gets(a); printf(“\nThe name enterd is : %s”,a); printf(“\nLength of string is : %d”,strlen(a)); getch(); return 0; } 该程序不包含警告或错误。 在运行时,我输入值“ melwinsunny ”作为输入。 没有错误,显示的结果是: Enter the name : melwinsunny The name entered is : melwinsunny length of string is : 11 为什么会这样? 我已经声明了长度为4的字符数组( char a […]