Client/server in C ( linux )

This is a discussion on Client/server in C ( linux ) within the C Programming forums, part of the General Programming Boards category; 1) assigning a normal char array[], to another char *array[i], ( the result suggests so ) thanks in advance BujarM...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    5

    Client/server in C ( linux )

    1) assigning a normal char array[], to another char *array[i], ( the result suggests so )


    thanks in advance
    BujarM
    Last edited by BujarM; 04-19-2009 at 04:55 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I've written client server stuff for linux but I won't even look* at this until you do a better job of summarizing your real problems and asking specific questions. For example:
    Code:
    1) assigning a normal char array[], to another char *array[i], ( the result suggests so )
    Sounds like a very basic issue you could test yourself, and then post <10 lines of code to represent your difficulty. But if you are too lazy, what makes you think someone else will scan through a few hundred lines of TOTALLY IRRELEVANT detail to sort this now very very vague statement out??

    Good luck.

    *relax, someone else might!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Quote Originally Posted by MK27 View Post
    I've written client server stuff for linux but I won't even look* at this until you do a better job of summarizing your real problems and asking specific questions. For example:
    Code:
    1) assigning a normal char array[], to another char *array[i], ( the result suggests so )
    Sounds like a very basic issue you could test yourself, and then post <10 lines of code to represent your difficulty. But if you are too lazy, what makes you think someone else will scan through a few hundred lines of TOTALLY IRRELEVANT detail to sort this now very very vague statement out??

    Good luck.

    *relax, someone else might!

    you make a good point, but i already covered this
    i did test it in VS and GCC, and it works
    thats why im soo confused,
    i am just hoping someone with more experience
    can point out my errors


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
        while(1)
    	{
        char *client_balance[]={"20000", "18000", "16000", "14000", "12000"};
        int client_num=2;
        char buf[256];
      
        printf("Please type the new BALANCE:");
        fgets(buf,256,stdin);
    	buf[6]='\0';
        printf("%s\n", buf);
    	client_balance[client_num]=buf;
    
    	printf("%s\n",client_balance[client_num]);
    	}
        
       
      system("PAUSE");    
      return 0;
    }
    Last edited by BujarM; 04-19-2009 at 04:32 PM.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Okay, there are a few problems with your last post. They may or may not relate to your problem, but they do represent either a significant misunderstanding of some fundamentals, or some slightly bizarre methodology:
    • fgets adds a '\0'; you don't have to (or is this intended to curtail the size of the input?)
    • buf[6] is the seventh element of buf (counting from 0), and the items in client_balance are 5+1=6 (this is okay, since you are swapping pointers and not copying; I just wanted to make sure you get that -- otherwise why curtail the input at 6?).


    But I don't see anything wrong with:
    Code:
    client_balance[client_num]=buf;
    Why don't you post a small chunk of your Original Post containing the code which parallels this problem and explain what you mean by "the results suggest a logical bug" (I haven't compiled it and I won't be; sorry).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    5
    Quote Originally Posted by MK27 View Post
    • fgets adds a '\0'; you don't have to (or is this intended to curtail the size of the input?)
    • buf[6] is the seventh element of buf (counting from 0), and the items in client_balance are 5+1=6 (this is okay, since you are swapping pointers and not copying; I just wanted to make sure you get that -- otherwise why curtail the input at 6?).
    i am restricting the length to 6, i.e. end the buffer manually
    when dealing with large amounts of code to debug in a command-line compiler,
    you tend to be safe, than sorry.( :/ )


    Quote Originally Posted by MK27 View Post
    But I don't see anything wrong with:
    Code:
    client_balance[client_num]=buf;
    thank you for confirming this


    Quote Originally Posted by MK27 View Post
    (I haven't compiled it and I won't be; sorry).
    i totally understand, i know its too many lines of code
    i think im going to proceed alone and correct the code
    thanks.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thinking of upgrading to linux...
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 07-24-2009, 12:40 PM
  2. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 12:03 PM
  3. Dabbling with Linux.
    By Hunter2 in forum Tech Board
    Replies: 21
    Last Post: 04-21-2005, 05:17 PM
  4. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM

Tags for this Thread


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