C Programming Help What does this error message mean and how do I fix it?
@saifoo.khan @e.mccormick
One sec I'm posting it..
#include <stdio.h> #include <cs50.h> #include <ctype.h> #include <stdlib.h> #include <string.h> int main(int words, string letters[]) { if(words < 2) { printf("Usage: ./caesar <phrases>\n"); return 0; } else { printf("What is the key?"); int key = GetInt(); for(int x = 1; x < words-2; ++x) { for (int y = 0; y < strlen(letters) - 1; ++y) { printf("%d", key); } } } } Here is my code.
jharvard@appliance (~/pset2): make caesar clang -ggdb3 -O0 -std=c99 -Wall -Werror caesar.c -lcs50 -lm -o caesar caesar.c:20:40: error: incompatible pointer types passing 'string *' (aka 'char **') to parameter of type 'const char *'; dereference with * [-Werror,-Wincompatible-pointer-types] for (int y = 0; y < strlen(letters) - 1; ++y) ^~~~~~~ * /usr/include/string.h:399:35: note: passing argument to parameter '__s' here extern size_t strlen (const char *__s) ^ 1 error generated. make: *** [caesar] Error 1 And here is the error message. Should I take a screenshot or is this good? @saifoo.khan
@confluxepic Can you help?
@ikram002p @CausticSyndicalist @rvc @paki
@sleepyjess :)
@Jaynator495
HELLO!!!
Please help this poor fellow
>_<
One momment ill read it... *Gives evil glance over at sleepyjess*
Lol
Should I take a screenshot?
Before I read it, What programming language is it so i know if i can help or not XD
Read the question xD- It's in C
At the top lol
Theres a language called "C" ._. Learn somethign new every day XD
Ya, and C++
I know of c++ ._.
So you can'tz Helpz mez? meowww
Let me see if I can spot someone that can though xD
where's the ambassador help page
strlen = You want to determine the length of the array, right?
No it is to determine the length of the string that is in the parentheses- called letters
Length of string on which index of array? :P
Ummm.. Idk. By the way you know C programming right?
Here's a video that can help... http://cs50.tv/2012/fall/shorts/command_line_arguments/command_line_arguments-720p.mp4
I've never seen this error message before and I can't find anything wrong..
See, when you want to check something in an array (even if you want to check the length of the string inside the index[0]), you still need to give it the index of the array where you want to apply strlen().
Sorry i was watching the video.
I see what the problem is. You're passing a string array. Whereas you should be passing a char* agrv[].
As char* argv is a pointer type array.
Hmmm... I just started learning C I don't understand Sorry :C
Umm, don't know about pointers? Don't worry, you'll learn them at a later stage. For now, just change it to char* argv[].
umok
wait what should i change to char* argv[]
change strlen(letters) to strlen(*letters)
string is of type 'point to a pointer of a char'. strlen method expects type 'pointer to a char'. So you need to 'derefence' the letters variable. Hence the operator * in front of it.
@confluxepic why dont u accept messages?
I changed my settings now. @DavidUsa
@e.mccormick Please help, I still need it :)
What issue are you having now? Stillt he same one or something else?
Something else. I'll post now so I can give you medal :)
Calculate strlen once, store it, then use it as a condition. Don't use a linear \(O(n)\) solution to a constant \(O(1)\) problem.
The problem here is that `letters` is an array of `string`s. You only want to pass in a single `string`. For example, if they ran the command ``` ./caesar I am the law. ``` Then we'd have data similar to: ``` letters[0] = "I"; letters[1] = "am"; letters[2] = "the"; letters[3] = "law."; words = 4; ``` First you want to iterate through your words. Then you can iterate through each letter of each word. By the way `*letters` is no different that `letters[0]`.
@wio why are you replying to a closed quesition? :P
Join our real-time social learning platform and learn together with your friends!