Printing strings columnwise

Discussion in 'C Programming' started by Umesh, Aug 20, 2007.

  1. Umesh

    Umesh Guest

    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.
     
    Umesh, Aug 20, 2007
    #1
    1. Advertising

  2. Umesh

    pete Guest

    Umesh wrote:
    >
    > 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 */


    --
    pete
     
    pete, Aug 20, 2007
    #2
    1. Advertising

  3. Umesh

    Umesh Guest

    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.

    pete wrote:
    > Umesh wrote:
    > >
    > > 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 */
    >
    >
    > --
    > pete
     
    Umesh, Aug 20, 2007
    #3
  4. Umesh

    pete Guest

    Umesh wrote:
    >
    > 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(2,0); but it is not working.


    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.

    --
    pete
     
    pete, Aug 20, 2007
    #4
  5. Umesh

    Umesh Guest

    Got it!

    #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:
    > Umesh wrote:
    > >
    > > 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(2,0); but it is not working.

    >
    > 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.
    >
    > --
    > pete
     
    Umesh, Aug 20, 2007
    #5
  6. Re: Got it!

    Umesh <> writes:
    > #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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 20, 2007
    #6
  7. Umesh

    Umesh Guest

    Re: Got it!

    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

    Umesh wrote:
    > #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:
    > > Umesh wrote:
    > > >
    > > > 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(2,0); but it is not working.

    > >
    > > 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.
    > >
    > > --
    > > pete
     
    Umesh, Aug 21, 2007
    #7
  8. Umesh

    Army1987 Guest

    Re: Got it!

    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]
    --
    Army1987 (Replace "NOSPAM" with "email")
    No-one ever won a game by resigning. -- S. Tartakower
     
    Army1987, Aug 21, 2007
    #8
  9. Umesh

    Ian Collins Guest

    Re: Got it!

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

    Still too rude to post correctly I see..

    --
    Ian Collins.
     
    Ian Collins, Aug 21, 2007
    #9
  10. Re: Got it!

    Umesh <> writes:
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 21, 2007
    #10
  11. Re: Got it!

    In article <>,
    Ian Collins <> wrote:
    >Umesh wrote:
    >> But this doesn't work when i try to put the output in a text file
    >>

    >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!
     
    Kenny McCormack, Aug 21, 2007
    #11
  12. Re: Got it!

    In article <>,
    Keith Thompson <> wrote:
    >Umesh <> writes:
    >> 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).


    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.
     
    Kenny McCormack, Aug 21, 2007
    #12
  13. Re: Got it!

    "Kenny McCormack" <> schrieb im Newsbeitrag
    news:faekb4$p7a$...
    > In article <>,
    > Ian Collins <> wrote:
    >>Umesh wrote:
    >>> But this doesn't work when i try to put the output in a text file
    >>>

    >>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!

    What country, France, Netherlands, Laos, Kuba?
     
    Joachim Schmitz, Aug 21, 2007
    #13
  14. Umesh

    Richard Bos Guest

    Re: Got it!

    "Joachim Schmitz" <> wrote:

    > "Kenny McCormack" <> schrieb im Newsbeitrag
    > news:faekb4$p7a$...
    > > In article <>,
    > > Ian Collins <> wrote:
    > >>Umesh wrote:
    > >>> But this doesn't work when i try to put the output in a text file
    > >>>
    > >>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!


    > What country, France, Netherlands, Laos, Kuba?


    Well, since they were our colours first...

    Richard
     
    Richard Bos, Aug 21, 2007
    #14
  15. Re: Got it!

    Keith Thompson said:

    > Umesh <> writes:


    <snip>

    >> 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).


    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?

    --
    Richard Heathfield <http://www.cpax.org.uk>
    Email: -www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999
     
    Richard Heathfield, Aug 21, 2007
    #15
  16. Re: Got it!

    >>>>> "RH" == Richard Heathfield <> writes:

    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


    --
    Charlton Wilbur
     
    Charlton Wilbur, Aug 21, 2007
    #16
  17. Re: Got it!

    Charlton Wilbur <> writes:
    >>>>>> "RH" == Richard Heathfield <> writes:

    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Aug 21, 2007
    #17
  18. Umesh

    CBFalconer Guest

    Re: Got it!

    Ian Collins wrote:
    > Umesh wrote:
    >
    >> But this doesn't work when i try to put the output in a text file

    >
    > Still too rude to post correctly I see..


    I have him/her/it plonked from way back, and the only annotation is
    "hopeless".

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    CBFalconer, Aug 21, 2007
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,614
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. Sobhan

    Reading Columnwise in a file

    Sobhan, Feb 6, 2004, in forum: C++
    Replies:
    3
    Views:
    1,019
    John Harrison
    Feb 7, 2004
  3. JustSomeGuy
    Replies:
    13
    Views:
    529
    msalters
    Dec 9, 2004
  4. Sobhan

    How to read data columnwise

    Sobhan, Feb 6, 2004, in forum: C Programming
    Replies:
    3
    Views:
    503
    Joe Wright
    Feb 7, 2004
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    810
    Malcolm
    Jun 24, 2006
Loading...

Share This Page