dimanche 1 mars 2015

How do I remove overflow characters or append characters in a given string in C?


I basically wanna have an arbitrary length string but a fixed size output string. So if i assign x a string of 10 characters, I want to end up with a string of 5 characters at the second printf. And if x is 3 characters, I wanna add on blanks to make the string 5 characters. Here is my code so far, but its not working because I can't even access an index, it segfaults;



int main()
{
char x[] = "d dddddddd";
printf(x);
printf("");
// seperate
printf(x[1]);
return 0;
}


thanks, i wonder whether this is possible in c, but you could also atyempt it in c++




Aucun commentaire:

Enregistrer un commentaire