+ 2
[Solved] Do I need to output an end of file or end of line?
Code challenge: splitting strings. I'm passing #1,3,4 but failing #2 & 5. I can see my output matches the required output for #2, is there something I'm overlooking?? When debugging: I printed a single character after my output code, doesn't seem to be hiding any unexpected space/tabs. What else should I check? https://code.sololearn.com/cHBtcwQYSB3o/?ref=app
2 Antworten
+ 4
The issue is that you are printing characters past the end of the string if the string size is not a multiple of the segment size. You need to make sure to exit the loop at the null terminator, for example by adding "... && inwards[i] != '\0'" to the condition of the inner loop. The outcommented break statement seems like you had the right idea already, it just would have to be placed before the output statement.
Your debugging attempts failed because not all characters have a graphical representation on the console, so there is no way to see them as such, although they are still in the output buffer (and thus are compared to the expected output). Printing the characters as integers instead allows you to seem them (rather their ASCII values).
0
You are given a word and want to split it into even parts based on a number that is provided, each half being the size of the number.
Task:
Write a program that takes in a string, and a number as input.
Split the string into even parts sized by the number, and output the parts separated by hyphens.
The last part of the output will be any leftover, as the input string might not split into the provided parts evenly.
Input Format:
Two inputs: a string and an integer.
Output Format:
A string, representing the hyphen-separated parts.
Sample Input:
hello
2
Sample Output:
he-ll-o