Is the strlen function used this way?
If not what would be the alternative?Code:Insert(char *s, int index) { int size_of_string = Size(); int length = strlen(s); int sum = size_of_string + sum; }
Is the strlen function used this way?
If not what would be the alternative?Code:Insert(char *s, int index) { int size_of_string = Size(); int length = strlen(s); int sum = size_of_string + sum; }
strlen takes the length of a char* string. I don't know what you're trying to do with your code. char* strings are passed by pointer when they're given as arguments. (No extra copy is made, so any modifications made to that string are still there when that function exits.)
Info about strlen e.i. arguments and return values.
Try and print the variable sum. Not as expected? Why? Variable sum contains a garbage value. If this was a pointer variable you would have a serious BUG.Code:Insert(char *s, int index) { int size_of_string = Size(); int length = strlen(s); int sum = size_of_string + sum;//This line is dangerous because sum is uninitialized }
Solution: Always initialize a variable when it is possible!
01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
Good things donīt come easy in life!!!