User Profile

Collapse

Profile Sidebar

Collapse
boddah
boddah
Last Activity: Feb 11 '11, 02:10 AM
Joined: Dec 26 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • boddah
    started a topic How to copy char * to char *array?
    in C

    How to copy char * to char *array?

    Hi all,
    I've been working on this code since morning and seems like I need stronger skills on pointers n arrays.
    I'm trying to read the content of a config file, which has x lines and then pass it to an array of characters.

    Not really sure if I did use the strtok function correctly, but here's what I got so far..

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include <string.h>
    ...
    See more | Go to post

  • After creating the 1st socket, a client successfully connects to it and closed its connection. When the server tries to bind for the second socket, it fails and the app exits. Hence, the 2nd client unable to connect. Any way i can solve this?
    See more | Go to post

    Leave a comment:


  • Yes Raghul, I'm aware of that. But still I'm unable to bind the socket to the port....
    See more | Go to post

    Leave a comment:


  • boddah
    started a topic socket programming in C + multiple socket, same port num
    in C

    socket programming in C + multiple socket, same port num

    Hi all,
    I was trying to create 2 sockets to be able to establish 2 connections to a client. The first socket supposedly to facilitate the DH algo which I wanted to implement and the second socket to only accept byte streams as input. I always get "unable to bind" even though I've used the close() and shutdown() function to close the first socket. Can anyone help show me the way here?
    See more | Go to post

  • boddah
    replied to memcopying to a variable
    in C
    char temp[20];
    int a=0;
    for(int i=0;i<10;i++)
    {
    printf("%d", 20 * i);
    memcpy(temp[a], 2 * i, 1);
    a++;
    }
    Hi again. Sorry I forgot to include the initialization of a=0 in the 2nd snippet. Actually the for loop will printf an output of something like this printf("%c%c", <some formula here>);
    the for loop doesn't iterate at a fixed num so I'm just initializing...
    See more | Go to post

    Leave a comment:


  • boddah
    started a topic memcopying to a variable
    in C

    memcopying to a variable

    Hi guys, I'm trying to copy the output from the for loop to a variable 'temp'

    for(int i=1;i<4;i++)
    {
    printf("%s", 2 * i); //outputs - 246
    }
    printf("\n");

    ----------------------------------------------------------
    I've tried this to only get 'segmentation fault'

    char temp[20];
    int a;
    for(int i=0;i<10;i++)
    {
    ...
    See more | Go to post

  • boddah
    replied to trouble with fork() and exec()
    in C
    Here's my fork & exec code:

    Code:
    , "Fork failed.\n");
    		log_messaint spawn(int b, int a)
    {
    	int result;
    	char msg[MAXLINE];
    	pid_t mypid;
    
    	mypid = fork();
    
    	if(mypid < 0)
    	{
    		sprintf(msgge(RM_LOG_FILE, msg);
    	}
    	else if(mypid == 0)
    	{
    		printf("I'm the child\n");
    		result = execlp("./myApp",
    ...
    See more | Go to post

    Leave a comment:


  • boddah
    replied to trouble with fork() and exec()
    in C
    Problem solved. Actually the prob wasn't with my Parent code but it was the other program code which I was trying to spawn. Added a while(1){} to the code and it worked well. Previously the code had exited (thru return 0) thus, resulting the myApp to appear <defunct> when spawned.
    Thanks Raghu and cheers....
    See more | Go to post

    Leave a comment:


  • boddah
    replied to trouble with fork() and exec()
    in C
    Thanks gpraghuram. I'll go thru the PDF file and update here again. BTW, do u have any sample of urs which I can refer to as well?
    See more | Go to post

    Leave a comment:


  • boddah
    started a topic trouble with fork() and exec()
    in C

    trouble with fork() and exec()

    Hi all,
    I'm writing a manager application (Linux/C++) that'll spawn 2 instances of a program (myApp). The myApp program needs to stay alive after being spawned (both instances) so a 3rd party program could connect to them thru socket. My problem is at the fork and exec function which I'm not really familiar with yet. Could anyone help to point me in the right direction or maybe enlighten me with the correct usage of fork and exec.
    Thanks...
    See more | Go to post

  • boddah
    replied to concatenating elements of an array
    in C
    ah..yes, no prob. it's supposed to be cr. my typo...
    See more | Go to post

    Leave a comment:


  • boddah
    replied to concatenating elements of an array
    in C
    man..i still can't solve this.

    unsigned char array[20];
    char cr[21];
    strncpy(cr, (char*)array,20 );
    printf("aha:%s\ n",pcr);

    -it still gives me segmentation fault. can someone pls help?
    See more | Go to post

    Leave a comment:


  • boddah
    replied to concatenating elements of an array
    in C
    Thanks Jos...I've been using malloc and new but i always get a segmentation fault. I'm quite new to all this malloc and sizeof....
    See more | Go to post

    Leave a comment:


  • boddah
    replied to concatenating elements of an array
    in C
    man...segmentat ion error..i cant figure it out. so i just use a short-cut. Write and append all those arrays to a file and then read 'em back as a string. thanks all
    See more | Go to post

    Leave a comment:


  • boddah
    started a topic concatenating elements of an array
    in C

    concatenating elements of an array

    Hi all,
    I've been trying to get this working for days but I still couldn't get it.

    snippet:
    unsigned char *a;
    unsigned msg[5];

    I want to concatenate all 5 elements from array msg to the unsigned char *a.
    Lets say
    msg[0]="abc";
    msg[1]="def";
    msg[2]="ghi";
    msg[3]="jkl";
    msg[4]="mno";

    and in the end a would point...
    See more | Go to post
No activity results to display
Show More
Working...