The task is:
Text file contains words. Enclose words beginning with a consonant in double quotes.
Actually, as I try to solve it: We read text by character into an array of characters, if the character is capital, then we assign the current element to an empty variable, an opening quote to the current element, a variable to the next element, and a closing quote to the next element, and so with each element in the loop. The problem is that the compiler swears at the line "if (a [i] ==" A "," B ")" writes the following:
have incompatible types 'char' and 'char *'
Before that, I often wrote on php and there were no such problems.
#include <stdio.h> int main(int argc, char *argv[]) { char a[1000]; int count=0; FILE *file = fopen("1.txt", "rw"); for(int i=0;!feof(file);i++){ a[i]=fgetc(file); if(a[i] == 'A'){ } count++; } for(int i=0;i<count;i++){ printf("%c",a[i]); } fclose(file); printf("\n"); return 0; }
a[i]) with a pointer to characters ("A"(yes, a string constant is an array of characters and, in a sense, means a pointer)), so the compiler swears at that. Well, and even if you write syntactically correctlyif (a[i] == 'A','B'), then this will not be what you wanted. - avpfeof. And the last thing - you shouldn’t fix the correct code in the question : you put everyone in a stupid position, including yourself: ask why the correct code doesn’t work ... - Harry