Где ошибка? Или можно по другому как то написать? - C (СИ)
Формулировка задачи:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, const char * argv[]) {
printf("Enter text");
char text[300];
gets(text);
printf("You entered: %s", text);
// validate text
char command[10];
while (strcmp(command, "exit") != 0) {
printf("A All letters toupper\n");
printf("B All letters to tolower\n");
printf("C First letter to lowwer\n");
printf("Enter command:");
gets(command);
if (strcmp(command, "A") == 0) {
printf("Command A:\n");
printf("Original text: %s\n", text);
//char newText = toupper(*text);
char newText[300];
strcpy(newText, text);
for (int i = 0; newText[i]; i++) {
newText[i] = toupper(newText[i]);
}
printf("New text: %s\n", newText);
} else if (strcmp(command, "B") == 0) {
printf("Command B:\n");
printf("Original text: %s\n", text);
//char newText=tolower(*text);
char newText[300];
strcpy(newText, text);
for (int i = 0; newText[i]; i++) {
newText[i] = tolower(newText[i]);
}
}
printf("New text: %s\n", newText);
else (strcmp(command, "C") == 0) {
printf("Command C:\n");
printf("Original text: %s]n", text);
//char newText=touuper(*text);
char newText[300];
strcpy(newText, text);
for(i=1;i<text;i++) {
if(text[i-1]==' ')
newtext[i]=toupper(text[i]);
else
newtext[i]=text[i];
}
}
}
}Решение задачи: «Где ошибка? Или можно по другому как то написать?»
textual
Листинг программы
for(i=1;i<text;i++)