-
well i fixed my problem
i used %.29s flag with printf to limit the number of chars printed and i removed that whole for loop and used
Code:
while (playtime[i]!=0)/* if playtime ==0 then there is no song there*/
{
mins = 0;/* tryint to make it obvious if convert method isnt working*/
secs = 0;/* by initializeing mins and secs or each new song to 0*/
convertSecondsToMinutes(&mins, &secs, playtime[i]);
titles[i][(strlen(titles[i])-1)] = '\0'; /* this is how i found
the newline char and replace
it with null, then i just printed
a newline at the end of my real
printf statemnet*/
if (select[i] == 1)
{
printf("*");/* indicates song is selected*/
}
else
{
printf(" ");/* holds place of * to keep spaceing same*/
}
printf("[%1d]%3d:%02d %.30s\n", i+1, mins, secs, titles[i] );/* prints song info...*/
i++;
-
i used strlen() to find the end of the string and i knew the new line char was the second from last beacuse the null is last and i replaced it with null
-
that didnt work as good as i hoped it would
this found the newline and replaced it with null
Code:
for(j=0; j<30; j++)
{
if(titles[i][j]=='\n')
{
titles[i][j] = '\0';
}
}
-
>titles[i][(strlen(titles[i])-1)] = '\0';
That's not such a hot idea. A while back we tossed around a slew of ideas for removing the newline, and the usual consensus is that your best option is something like this:
Code:
void trim_newline ( char s[] )
{
char *newline = strrchr ( s, '\n' );
if ( newline != NULL )
*newline = '\0';
}
Of course, that assumes that there may be more than one newline and you want to snip the last one. If you know that there will only be one newline, such as with the result of fgets, you should probably be using strchr. Some implementations of strrchr can be noticeably slower.
-
Presumably because they use strlen() first. Then again, I've never really heard anything from the local shock jock with a newline in its name...