Thread: strsize question

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    45

    strsize question

    So far I have the prototype for a function, and I called it strsize.

    int strsize ( char * str ) ;

    now what I need to do is write a complete function called strsize which counts the number of characters in the string passed to it (excluding null) and returns the size to the caller.

    And I cant use any library functions.

    How In the hell am I supposed to do this?

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Why not use strlen ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Happy_Reaper View Post
    Why not use strlen ?
    In other words, he should do what the assignment says not to do? How helpful is that?

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    I cant use library functions, strlen is a library function. so that doesnt help

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I didn't mean that, I meant use the code that's used for strlen.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    huh?

  7. #7
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    "strlen code" --> Google Search
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Just loop through the string that's passed to your function until you hit the '\0'. The number of times you iterate through the loop is the number of characters in the string. Return that number.
    If you understand what you're doing, you're not learning anything.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by The OP
    To whom it may concern:

    I am far too stupid to figure out my homework, even though I know the definition of a string, and even though we've convered loops in class, and variables and such. Can you do this task for me? I don't have the mental facilities to do this myself and/or I wasn't paying attention in class for, well, anything at all, and/or I haven't done any homework ever.

    Thanks,

    OP
    That's what you meant to say, right?


    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quzah, you're killing me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM