![]() |
|
#1
|
|||
|
|||
strlen concept question?Hey everyone...just a quick question. I'm given the expression:
Code:
Isn't there something wrong with this? I'm just not sure and need some advice. I'm just not sure what its value is. Thanks in advance for any help |
|
#2
|
|||
|
|||
Re: strlen concept question?Quote:
I'll answer the question with a few questions of my own. Answers to my questions would enable someone to answer your question. 1. What is the data type of S in this program? 2. What is the data type of the argument of the C Standard Library function strlen(), and is the data type of S compatible with the argument of strlen()?? 3. What is the data type of the function strlen()? 4. Is the value of the expression S+strlen(S) defined. (That is: is it a legal expression?) 5. If the answer to my question 4 is "yes", then what is the data type of the result of evaluating that expression? 6. If the answer to my question 4 is "yes", then is the answer to my question number 5 something that is compatible with the argument of the strlen()? If you get all of the way through to question 6 and the answer to question 6 is "yes", then it is a legal C expression. Whether there is something "wrong" depends on you, since a value judgment of "wrong" depends on what you expect it to be (or whoever it was who asked the question in the first place) . For example, suppose the answers lead to a "yes" for number 6. Are there any particular things that you have to know about the data in the program to guarantee that the value of the expression is defined? (And the only data item is S, so the question is "What do you have to know about the value of S to be able to know the value of the expression?") Regards, Dave |
|
#3
|
|||
|
|||
Re: strlen concept question?I'm sorry about the vagueness of my question. I apologize. To expand a little.
I'm given a string S in a character array. This is all I'm given(those words exactly). I'm suppose to know if the expression: strlen(S+strlen(S)) has a value of 0,1,will generate an error, or if the value will just depend on the contents of S. I agree that this question doesn't come with a lot of information. I guess you feel my pain though. I truly do appreciate any and all advice though. Thanks |
|
#4
|
|||
|
|||
Re: strlen concept question?Quote:
I understood the question OK, I think. And, yes, I realize that no one was born knowing this stuff, and it's all kind of confusing at times. (Not just at first, but, perhaps, especially at first.) So, have you started on the list of questions? I tried to make a sequence that would lead to some discovery in a logical order rather than just saying yes/no at the bottom line and then trying to work out why. I intended for you to answer the questions, not give me more information so that I could answer them. For example the data type of the function strlen() is int, right? So, make up some char array, put a null-terminated sequence of chars and feed the elements of the expression to your compiler. If the compiler gives some error or warning messages about the program, then you can investigate the cause. If the program compiles OK, then you can try to see what the value of the expression is. (Assign it to an int variable and print out the value.) Here: I'll get you started CPP / C++ / C Code:
Now, if you are supposed to do this without a computer, then write the program anyhow, and pretend you are the computer. Do it a step at a time. Regards Dave "We can face our problem. We can arrange such facts as we have with order and method." Hercule Poirot --- in Murder on the Orient Express |
|
#5
|
|||
|
|||
Re: strlen concept question?Quote:
__________________
Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with. |
|
#6
|
|||
|
|||
Re: strlen concept question?Thank you Dave. With your help I was able to figure out the answer to my question, which was that the expression returns a 0 for any type of string that is entered. Thanks again for the help. I appreciate it.
|
|
#7
|
|||
|
|||
Re: strlen concept question?Quote:
"I love it when a plan comes together." ---Hannibal Smith (George Peppard, 1928-1994) The A Team, 1983-1987 Regards, Dave |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Check This New Searchengine Concept Out ! | onauc | Search Engine Optimization Forum | 5 | 10-Feb-2006 11:23 |
| non-member function question | crq | C++ Forum | 1 | 03-Feb-2005 22:59 |
| Simple question on arrays--please help! | brookeville | C++ Forum | 16 | 18-Nov-2004 00:23 |
| Repetition structure problem and question | brookeville | C++ Forum | 17 | 29-Oct-2004 18:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The