The problem enlies with printf(stringOut). It prints an empty array. The function halfstring appears to work correctly but the string it builds never makes it to main.
int main(int argc, char *argv[])
{
char stringIn[30] = "There is no cow level.\0";
char stringOut[sizeof(stringIn)];
halfstring(stringIn, stringOut);
printf(stringOut);
return 0;
}
halfstring is supposed to take every odd character in a char array and put it into a new char array without using ANY system-defined string functions (i.e. those found in the string.h library including strlen, strcat, strcpy, etc).
void halfstring(char stringIn [], char stringOut [])
{
int i = 0;
int modi;
while(stringIn[i] != '\0')
{
if(i % 2 != 0)
{
stringOut[i] = stringIn[i];
}
i++;
}
}
halfstring()
function is totally broken. Step through it by hand or with a debugger. – John ZwinckstringOut[i] = stringIn[i];
-->int k=0;
...stringOut[k++] = stringIn[i];
...stringOut[k] = '\0';
– BLUEPIXYstringOut
. You need to index the two array,stringIn
andstringOut
separately - so with different variables, like BLUEPIXY wrote. – agiro