Printing strings columnwise

U

Umesh

I was just wondering how to print two strings coulmnwise.

char string1[]="abcd";
char string2[]="efgh";

now i want to print something like this:

a e
b f
c g
d h

i was trying to use gotoxy(2,0); but it is not working.
 
P

pete

Umesh said:
I was just wondering how to print two strings coulmnwise.

char string1[]="abcd";
char string2[]="efgh";

now i want to print something like this:

a e
b f
c g
d h

i was trying to use gotoxy(2,0); but it is not working.

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
char string1[]="abcd";
char string2[]="efgh";
size_t index;

for (index = 0; index != sizeof string1 ; ++index) {
printf("%c %c\n", string1[index], string2[index]);
}
return 0;
}

/* END new.c */
 
U

Umesh

Thank you. But in my program i need to print the first sequnce first
and then the second sequnce. I hope u understand my problem.

After printing the first sequence in the first column I've to print
the second sequence in the second column.
Umesh said:
I was just wondering how to print two strings coulmnwise.

char string1[]="abcd";
char string2[]="efgh";

now i want to print something like this:

a e
b f
c g
d h

i was trying to use gotoxy(2,0); but it is not working.

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
char string1[]="abcd";
char string2[]="efgh";
size_t index;

for (index = 0; index != sizeof string1 ; ++index) {
printf("%c %c\n", string1[index], string2[index]);
}
return 0;
}

/* END new.c */
 
P

pete

Umesh said:
Thank you. But in my program i need to print the first sequnce first
and then the second sequnce. I hope u understand my problem.

I don't.
After printing the first sequence in the first column I've to print
the second sequence in the second column.

Why?

gotoxy isn't part of the C standard library.
First, find out if you C implementation supports gotoxy;
then, if it does,
see what your implementation's documentation says about it.
 
U

Umesh

#include <stdio.h>
#include <conio.h>
#include<string.h>

int main(void)
{
char str1[]="abcd",str2[]="efgh";
int i;
for(i=0;i<strlen(str1);i++)
printf("%c\n",str1);
for(i=0;i<strlen(str2);i++)
{
gotoxy(2,i+1);
printf("%c\n",str2);
} //initial position is given by gotoxy(1,1);
return 0;

}
 
K

Keith Thompson

Umesh said:
#include <stdio.h>
#include <conio.h>
#include<string.h>

int main(void)
{
char str1[]="abcd",str2[]="efgh";
int i;
for(i=0;i<strlen(str1);i++)
printf("%c\n",str1);
for(i=0;i<strlen(str2);i++)
{
gotoxy(2,i+1);
printf("%c\n",str2);
} //initial position is given by gotoxy(1,1);
return 0;

}
pete wrote:

[snip]

Neither <conio.h> nor gotoxy() is part of standard C. If you have
questions about either of them, you need to post to a newsgroup where
they're topical, probably a Windows or DOS group.

Please don't top-post. Read the following to understand what
top-posting is and why it's discouraged:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

Please don't change the subject header when you post a followup. It
makes it difficult to follow the discussion. The original subject was
"Printing strings columnwise"; since you're still discussing that,
changing the subject header can only cause confusion.

I recall from your last flurry of postings here that you weren't very
good at listening to advice. I hope you've improved.
 
U

Umesh

But this doesn't work when i try to put the output in a text file

FILE *fout;
fout=fopen("c:/output.txt","w");

then fprintf etc

Hi, Keith i think it's better to work than to waste time giving
advices. thx
#include <stdio.h>
#include <conio.h>
#include<string.h>

int main(void)
{
char str1[]="abcd",str2[]="efgh";
int i;
for(i=0;i<strlen(str1);i++)
printf("%c\n",str1);
for(i=0;i<strlen(str2);i++)
{
gotoxy(2,i+1);
printf("%c\n",str2);
} //initial position is given by gotoxy(1,1);
return 0;

}
pete said:
I don't.


gotoxy isn't part of the C standard library.
First, find out if you C implementation supports gotoxy;
then, if it does,
see what your implementation's documentation says about it.
 
A

Army1987

On Tue, 21 Aug 2007 00:46:05 -0700, Umesh wrote:

[about writing stuff to stdout in a strange order]
But this doesn't work when i try to put the output in a text file

FILE *fout;
fout=fopen("c:/output.txt","w");

then fprintf etc
You cannot insert stuff in-place in a file. See FAQ 19.14.
If you *really* need that, try to write "a ", save the position
with ftell(), " \nb ", resave the position etc., then work with
fseek(). But I can't see why you can't write stuff in a normal
order, as pete suggests.
[nonstandard stuff snipped]
 
K

Keith Thompson

Umesh said:
But this doesn't work when i try to put the output in a text file

FILE *fout;
fout=fopen("c:/output.txt","w");

then fprintf etc

No, of course it doesn't work.
Hi, Keith i think it's better to work than to waste time giving
advices. thx

And if you weren't too rude to post properly, somebody might explain
why it doesn't work (or at least where you can ask).

Bye.
 
K

Kenny McCormack

Still too rude to post correctly I see..

It's called independence; not kowtowing to "The Man".
It's what made this country great. Hooray for the Red, White, and Blue!
 
K

Kenny McCormack

No, of course it doesn't work.


And if you weren't too rude to post properly, somebody might explain
why it doesn't work (or at least where you can ask).

Umesh, you must understand that, living as he does in his parent's
basement, Keith has nothing better to do than give (screwball) advice
here on clc.
 
J

Joachim Schmitz

Kenny McCormack said:
It's called independence; not kowtowing to "The Man".
It's what made this country great. Hooray for the Red, White, and Blue!
What country, France, Netherlands, Laos, Kuba?
 
R

Richard Heathfield

Keith Thompson said:
And if you weren't too rude to post properly, somebody might explain
why it doesn't work (or at least where you can ask).

Hey, Keith, come on, fair's fair - you keep telling people not to feed
the trolls, and it's patently obvious that Umesh is either a troll or
far more stupid than is generally considered possible for a human. What
are you doing - fattening him up for Christmas?
 
C

Charlton Wilbur

RH> Hey, Keith, come on, fair's fair - you keep telling people not
RH> to feed the trolls, and it's patently obvious that Umesh is
RH> either a troll or far more stupid than is generally considered
RH> possible for a human. What are you doing - fattening him up
RH> for Christmas?

Living in perpetual hope, it looks like from here.

Can't fault Keith for being an optimist.

Charlton
 
K

Keith Thompson

Charlton Wilbur said:
RH> Hey, Keith, come on, fair's fair - you keep telling people not
RH> to feed the trolls, and it's patently obvious that Umesh is
RH> either a troll or far more stupid than is generally considered
RH> possible for a human. What are you doing - fattening him up
RH> for Christmas?

Living in perpetual hope, it looks like from here.

Can't fault Keith for being an optimist.

Umesh hadn't posted for a while; I had hoped me might have learned
something during his absence, and I thought it couldn't hurt to give
him a chance to demonstrate it. Oh, well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top