Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

C Programming on the Mac L29 - Comparing strings

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,401
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jul 6, 2010

How to compare strings in C. //Note: strcmp returns either a -1, 0, or 1. Strncmp should also be used for buffer overflow purposes however it is not that crucial. http://en.wikipedia.org/wiki/Strcmp

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (AppleProgramming)

  • Why can't I just compare with "exit\0" and leave the input string as it is?

  • @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".

  • when is the \n actually written to get rid of? is that when we hit the enter key?

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

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

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

see all

All Comments (9)

Sign In or Sign Up now to post a comment!
  • @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.

  • just wondering, when we use 'fgets', we often feed input via 'stdin' or a file pointer. Whats the 'stdio' that we sometimes see with typing assistance?

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more