Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C do while循环中的字符串_C - Fatal编程技术网

C do while循环中的字符串

C do while循环中的字符串,c,C,改变 到 及 到 另外,不要忘记包括string.h您正在比较指针,而不是它们指向的字符串。看一看。另外,如果你在后面写两个字符串文字,它们将被编译器合并。那么,你有没有在调试器中检查过你的代码,检查过变量等等。?这是第一件要做的事。还可以阅读C中的字符串比较,因为[str1!=“END”]不起作用。这些是指针,谢谢。我做了这些改变,我仍然把它转换成拉丁语,而不仅仅是结束节目。我应该在那里的某个地方添加一个中断吗?只要添加if(strcmp(str,“END”)==0)中断在scanf之后,使用

改变


另外,不要忘记包括
string.h

您正在比较指针,而不是它们指向的字符串。看一看。另外,如果你在后面写两个字符串文字,它们将被编译器合并。那么,你有没有在调试器中检查过你的代码,检查过变量等等。?这是第一件要做的事。还可以阅读C中的字符串比较,因为[str1!=“END”]不起作用。这些是指针,谢谢。我做了这些改变,我仍然把它转换成拉丁语,而不仅仅是结束节目。我应该在那里的某个地方添加一个中断吗?只要添加
if(strcmp(str,“END”)==0)中断
scanf
之后,使用一个无限循环,类似于
for(;;)
while(1)
// PigLatinFinal.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

void Heading (void)
{
    printf("************************************************************\n");
    printf("*                        Pig Latin                         *\n");
    printf("*                                                          *\n");
    printf("*                                                          *\n");
    printf("*                     Welcome                              *\n");
    printf("*                                                          *\n");
    printf("* In this program, the user will enter a word in English   *\n");
    printf("* The program will then return the word in Pig Latin.      *\n");
    printf("* The word cannot be longer than 7 letters.  You can       *\n");
    printf("* translate as many words as you wish. Enter 'END' without *\n");
    printf("* the quotation marks to end the program. 'END is case     *\n");
    printf("* sensitive                                                *\n");
    printf("*                                                          *\n");
    printf("************************************************************\n");
    printf("\n\n\n\n");
}

int main(void)
{
    Heading();
    char str1[20];
    int i =0;
    do
        {

        int count =0;
        do
            {          
            printf("Enter a word in English for the program to return in Pig Latin: ");
            scanf("%s", str1);
            while(str1[count] != '\0')
            ++count;
            if (count>7)
                {
                printf("\n\nInvalid Entry. Please enter a word with no more than 7 letters\n\n");
                count=0;
                }
            }while (count>7);//loop to perform if invalid word is entered
         //while (count<7)
         //
        printf("\n%s in Pig Latin: ",str1);
        for (i=1;str1[i];++i)
            {
            printf("%c",str1[i]);
            }
        printf("%c",str1[0]);
        printf("ay");
        printf("\n\n\n");
         //}


    }while(str1!= "END"); 
return 0;
    }
}while (count>7);//loop to perform if invalid word is entered
}while (count==0);//loop to perform if invalid word is entered
}while(str1!= "END");
}while(strcmp(str1,"END")!=0);