Created
October 15, 2012 16:07
-
-
Save seanabraham/3893311 to your computer and use it in GitHub Desktop.
C strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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