Jump to content

strlen() and spaces

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
ClemsonCS

ClemsonCS

    Newbie

  • Members
  • PipPip
  • 28 posts
I am writing a simple parser (or so i thought) and have limited myself to the C libs. I am assuming that strlen() does not count spaces at the beginning of the char array because i am getting some bad results. How then, can I get a char array's length including the spaces? thanks!

EDIT

I am also wondering, how can I tell if a space was the first delimeter reached while using strtok()? I try to compare like so:
if(buff[index]==' ')
but this doesn't seem to work.

Edited by ClemsonCS, 02 February 2009 - 12:26 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You could search for the /0 character. It's position is the length, including spaces.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ClemsonCS

ClemsonCS

    Newbie

  • Members
  • PipPip
  • 28 posts
Okay thanks.

I now see that if I use a space as a delimeter with strtok(), strlen() will not count the spaces and if I use just '\0', the spaces are counted.