I have a question regarding a problem with a C program that I am doing. I am going to write two different lines next to each other in two columns. I did not find clear answers to my question, since they almost always give examples of numbers with a known length or quantity.
I have two lines, with a maximum length of 1500 characters, but for me an unknown length. Let for the sake of study these values be given:
char string1[] = "The independent country is not only self-governed nation with own authorities.";
char string2[] = "This status needs the international diplomatic recognition of sovereignty.";
I want to write them next to each other with a column width of twenty characters. I set the difference between the columns to a regular tab. Like this:
The independent coun This status needs th
try is not only self e international dipl
-governed nation wit omatic recognition o
h own authorities. f sovereignty.
, , , . . .
-, , , , , , c-, for-loops.
void display_columns(char *string1, char *string2);
int main()
{
char string1[] = "The independent country is not only self-governed nation with own authorities.";
char string2[] = "This status needs the international diplomatic recognition of sovereignty.";
display_columns(string1,string2);
}
void display_columns(char *string1, char *string2)
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0+20*i;j<20+20*i;j++)
{
printf("%c",string1[j]);
}
printf("\t");
for(j=0+20*i;j<20+20*i;j++)
{
printf("%c",string2[j]);
}
}
}