C Programming on the Mac L29 - Comparing strings

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

I was pretty sure I knew what the problem was, but for some reason it didn't seem to work on the previous examples you gave me. It's simply a compiler warning about converting to 32-bit types. You can change one of 2 things, you can change the variable to type size_t (unsigned long) or you can typecast the strlen() as an int: int len = (int)strlen(string); You can disable this warning in build settings by setting the warning for "Implicit Conversion to 32 Bit Type" to No. (mine is by default)

AppleProgramming
Автор

Thanks again. I am fixing the error with all the different ways you suggested, to become more familiar. It takes a bit of repetition to sink into this 44 year old brain. Im kinda thankful I took BASIC programming in 8th grade. IF/THEN, GOTO. Haha!
Thanks for all your help.
JmB

jmb
Автор

@RMH1565 Well you would be comparing "exit\n" because we are replacing that with the NULL character \0. \0 doesn't appear as a character so we just compare "exit".

AppleProgramming
Автор

@AwesomeChannel476 Yep, fgets will tack on the \n when you hit the return key.

AppleProgramming
Автор

@unifiedreality I think it is just some weird thing Xcode does. When you #include any of the header files it autofills anyone of them. If you #include string.h it will fill in string like it does with stdio. It is only meant to be a file pointer.

AppleProgramming
Автор

I don't know how you do that but you have to go to select your target in your project. Then under the "Build settings" tab, you search for implicit conversion and find the one that I mentioned and set it to no. Or you could fix the error as I suggested.

AppleProgramming
Автор

@deepak10066 A char* is any kind of string. So it just means you are passing in a C string.

AppleProgramming
Автор

why is it \0 in the function and not just 0?

b
Автор

All I can find are the behaviors to edit....so I turned off the Issue Navigator.
Good or bad?

jmb
Автор

Hi, i am trying to compare a character from the user input with a character of a word in a text file. i have tried using the strncmp, but it searches for the whole string not the character. if i type in the the whole word in the file it compares. i am trying to create the hangman program in C

endownedendownednoni
Автор

I receive the warning with the yellow ! in the triangle for this line of code.

int length = strlen(myString);

The error reads as follows;

Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int'

There is a little triangle under the s in strlen. Is this an indicator of the problem?

Sorry to bug, thx for the help.

JmB

jmb
Автор

In the function RepalceReturn(char *myString) why you used '*' for character?

deepak
welcome to shbcf.ru