CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

sizeof() and strlen() question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

sizeof() and strlen() question
PostPosted: Mon Feb 09, 2004 11:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 09, 2004 12:01 pm     Reply with quote

That is the way it's supposed to work, yes.
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Feb 09, 2004 3:14 pm     Reply with quote

Thought so. Thanks!
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Fri May 21, 2004 12:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 21, 2004 4:17 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group