View previous topic :: View next topic |
Author |
Message |
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
sizeof() and strlen() question |
Posted: Mon Feb 09, 2004 11:44 am |
|
|
Am I correct in my understanding that sizeof() will return the allocated space for an array, while strlen() will return the length of a string within that array?
In other words, if I have an array buffer[20] with a 10-character, null terminated string, strlen(buffer) would return 10 while sizeof(buffer) would return 20. Correct? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 09, 2004 12:01 pm |
|
|
That is the way it's supposed to work, yes. |
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Mon Feb 09, 2004 3:14 pm |
|
|
Thought so. Thanks! |
|
|
Kasper
Joined: 14 Jan 2004 Posts: 88 Location: Aurora, Ontario, Canada
|
|
Posted: Fri May 21, 2004 12:33 pm |
|
|
small question about strlen:
Code: |
#define Win_Log_Alarm "Alarm"
fprintf(PORT2,"strlen=[%u] ",strlen(Win_Log_Alarm));
|
the string length is always 0... what would be the better way of measuring the length of the string "alarm" |
|
|
Charlie U
Joined: 09 Sep 2003 Posts: 183 Location: Somewhere under water in the Great Lakes
|
|
Posted: Fri May 21, 2004 4:17 pm |
|
|
Try this:
Code: |
#define Win_Log_Alarm "Alarm"
int string_temp[10] = {0,0,0,0,0,0,0,0,0,0};
strcpy(string_temp, Win_Log_Alarm);
fprintf(PORT2,"strlen=[%u] ",strlen(string_temp));
|
Let us know if this works for you. |
|
|
|