Skip to content

Instantly share code, notes, and snippets.

@seanabraham
Created October 15, 2012 16:07
Show Gist options
  • Save seanabraham/3893311 to your computer and use it in GitHub Desktop.
Save seanabraham/3893311 to your computer and use it in GitHub Desktop.
C strings
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (void)
{
char *s = (char *) malloc(sizeof(char) * 10);
strcpy(s, "Hey man..");
int i = 0;
while (s[i++] != '\0')
{}
printf("strlen(s): %d, i-1: %d\n", (int) strlen(s), i-1);
// printf("sizeof(s): %d and strlen(s): %d and sizeof(char *): %d", (int) sizeof(s), (int) strlen(s), (int) sizeof(char *));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment