+ 3

Error message "array type has incomplete element type 'string[]'" in C programming

I wrote a function called cypher that returns a replaced value of vowels. I am stuck with the function "string cypher_word(string word[1][]);" and this prints out the error message. My code is below: #include <cs50.h> #include <stdio.h> #include <string.h> string cypher_word(string word[1][]); int main(int argc, string word[1]) { if (argc ==2) { printf("%s" , cypher_word); } else { printf("INVALID\n"); } string cypher_word(string word[1][]) { int i= 0, char ch[] = word[1][]; for (i=0; ch[i] != '\0'; i++) { switch(ch[i]); { case 1: { if (ch[i]== 'a')||(ch[i]== 'A') { ch[i]='6' } } case 2: { if (ch[i]== 'e')||(ch[i]== 'E') { ch[i]='3' } } case 3: { if (ch[i]== 'i')||(ch[i]== 'I') { ch[i]='1' } } case 4: { if (ch[i]== 'o')||(ch[i]== 'O') { ch[i]='0' } } } } return cypher_word; } } Can someone help me to fix this without using the pointer implementation. Thanks!

18th Feb 2023, 12:26 PM
Dupdaz
Dupdaz - avatar
4 Réponses
+ 10
Dupdaz The 'string' is an alias to 'char *' defined in cs50.h, so your declaration translates to: char *cypher_word(char *word[1][]); now 'word' array defined incorrectly, in multidimensional arrays, size of all dimensions should be defined (you can ignore the first one only). so thats one error. Also your main int main(int argc, string word[1]) is int main(int argc, char *word[1]) take care of that either. there are other syntax, structure and data type errors also. Decide whether you want to use 'if' or 'switch' statements, currently your code is like 10 times larger than it should be. btw you are already implementing and working with pointers.
18th Feb 2023, 1:29 PM
Tina
Tina - avatar
+ 3
Ipang perhaps you want to take a look at: https://cs50.harvard.edu/ap/2023/problems/2/no-vowels/ implementation details section. code doesn't seem to be machine generated (from syntax errors) but on the other hand resembles a translation or transliteration from algorithm to pseudo-code or from python to C. I highly doubt someone get argc right, write a correct for() loop on a string but miss all semicolons and praneteses inside it. or use switch together with ifs so I'm lost too 😅
18th Feb 2023, 6:52 PM
Tina
Tina - avatar
+ 1
Can you describe how your code was supposed to do vowel replacement? I'm lost at the switch...case blocks trying to understand why you compare <ch>[ i ] with integer and characters ...
18th Feb 2023, 5:22 PM
Ipang
+ 1
Thanks Tina 🇺🇦🇮🇷🇹🇷 Now it's clear what the OP was trying to do 🙏
19th Feb 2023, 3:22 AM
Ipang