So i was doing some coding exercice on Talentbuddy (for those who know), and i cant get why i cant finish this one. The exercice is removing a substring from a string, given as input the string, the position P where beginning to remove characters and N the number of characters needed to be remove.
Here is what i've done :
#include <stdio.h>
#include <unistd.h>
void remove_substring(char *s, int p, int n)
{
int idx;
idx = -1;
while (s[++idx] != '\0')
write(1, &s[idx == p - 1 ? idx + n : idx], 1);
}
When the input is "abcdefghi", P = 9 and N = 1, the result given is "abcdefgh" exactly the same as the one i get with my function. But TalentBuddy keep saying me that my output is wrong and i dont thing he (talentbuddy) is wrong. Maybe there is a blank space or something between the "h" and the '\0'. But i cant figure it cause when i add another write(1, "END", 3) at the end it appears like "abcdefghEND".
writeto output tostdout? Why not just useprintforputs? And it's unclear what you're saying your problem is.