Is there a better way to do this?Code:char line [173]; int x = -1; while(x++ <171) {line[x]= '-';} puts(line);
Is there a better way to do this?Code:char line [173]; int x = -1; while(x++ <171) {line[x]= '-';} puts(line);
Probably, look at memset(). But with either method you must also insure that you properly terminate the array to create a string.
It should work but it looks a bit funny to initialize x with -1 and increase x as long as it is smaller than 171
and indeed don't forget the terminating 0
I think the code looks better if you initialize x with 0 and and increase x as long as it is smaller than 173
For example:
Code:for(x = 0; x < 173; x++) line[x] = '-'; line[x] = (char) 0;
oeps, the for statement should count until x < 172 since one byte is needed for the 0 character
Jim Bluberg had already responded with a better solution. Zach Kleinstein.