Hello people,
I'm trying make right-justify the strings entered,
User enters different size of strings and I'm calculating their length and find the maximum of them...
For instance
First Input
-->str
Second Input
-->strin
Third
-->string
as partial What I've done is below
Code:
s_max=strlen(string[0].surname);
for(i=0;i<3;i++){
s_size = strlen(string[i].surname);
if( s_size > s_max){
s_max=(strlen(string[i].surname));
}
}
i=0;
do{
printf("%s\n",string[i].surname);//it's the part that I cant solve
i++;
}while(i!=3);
return 0;
}
the code above is a part of main func.,
I want to print strings as Right Aligned and as I'm doing this, I want to use reference the longest string ,i.e. printf("%6s\n",...) printf("%Ns",...)
What I cant do is that after I found the the longest string's length in for loop, how can I use that value while printing??
%x s if s_max is 7 it's gonna bi %7s....