why do my string only return one char instead whole of my string?

This is a discussion on why do my string only return one char instead whole of my string? within the C Programming forums, part of the General Programming Boards category; I been trying to figure out to get all of my string to show up. This code is being worked ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    13

    Unhappy why do my string only return one char instead whole of my string?

    I been trying to figure out to get all of my string to show up.
    This code is being worked on my freebsd machine.

    here is my code.

    ----------
    Code:
    void send_to_server(sendpattern, p1, p2, p3, p4, p5, p6, p7, p8, p9)
    char sendpattern[512];
    ///char *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
    char p1[512], p2[512], p3[512], p4[512], p5[512], p6[512], p7[512], p8[512], p9[512];
    
    {
            int success;
            sprintf(out, sendpattern, p1, p2, p3, p4, p5, p6, p7, p8, p9);
            strcat(out, "\n");
            success = write(sockfd, out, strlen(out));
            if (success < 1)
            reconnect_to_server(1);
            return;
    }
    
    
    
    
    ----------
    
    
    
    
                for (j = 0; j < width; j++)
                    if (i + j < len)
                        printf("%c", isprint(str[j]) ? str[j] : nonprint_char);
                        if (useirc) {
                        send_to_server("PRIVMSG %s :%c", IRCCHAN, isprint(str[j]) ? str[j] : nonprint_char);
                        ///say("%c", isprint(str[j]) ? str[j] : nonprint_char);
                        }
    -----------------

    printf works fine

    but

    send_to_server is not working as it should be


    the message appear like this

    &
    T

    instead of
    &blah
    The cookie have blue frosting.
    Last edited by Mouse_103; 01-30-2006 at 05:01 AM.
    Mouse

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    the format specifier for printing strings is %s... it appears that is the problem
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    13
    well it have to be %c in my program
    Mouse

  4. #4
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    well then you will need to cycle through the array using a loop
    so you can print the characters one at a time - here's an example:

    Code:
    int i;
    char string [20] = "something";
    
    for (i=0; i<20; i++)
    {
          printf ("%c", string [i]); /*cycling through the string, one char at a time*/
    }
    something like that will print ot an entire string... Hope that helps
    to some degree.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    13
    mmmmmmm

    printf works fine.
    send_to_server code is problem.
    Mouse

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 02:02 AM
  2. Alegro closes out on me
    By campsoup1988 in forum C++ Programming
    Replies: 8
    Last Post: 04-03-2006, 11:40 AM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  4. Memory leak - need help finding
    By ChadJohnson in forum C++ Programming
    Replies: 8
    Last Post: 04-06-2005, 08:26 PM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21