Problem with variables.

This is a discussion on Problem with variables. within the C Programming forums, part of the General Programming Boards category; Hi, i have some array of structs. the struct have : char job[max]; int number; i need to get numbers ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    14

    Problem with variables.

    Hi,
    i have some array of structs.
    the struct have : char job[max]; int number;
    i need to get numbers from the user and get the numbers to the struct with the names w1,w2,w3,etc.
    i dont understand how can i do it.
    how can i link between the "w" and the number (1,2,3).
    i cant with strcat.
    i will glad if someone can help me.
    Thanks.
    Or.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Do you mean if the user enters "23" you want to create a struct with job = "w23" and number = 23?

    Maybe you should post the code you tried so we can get a better idea of what you mean.
    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 claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Well that seems like code reflection and you can't do it in C. However I think you got the wrong idea; most likely you have to compare the input number to the number in the structs and do something with the ones that match.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by oror84 View Post
    Hi,
    i have some array of structs.
    the struct have : char job[max]; int number;
    i need to get numbers from the user and get the numbers to the struct with the names w1,w2,w3,etc.
    i dont understand how can i do it.
    how can i link between the "w" and the number (1,2,3).
    i cant with strcat.
    i will glad if someone can help me.
    Thanks.
    Or.
    First we're gonna need a lot better description of the job you're trying to do.
    Second, we're going to need a look at whatever code you have so far.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. variables problem ! (please help a noob)
    By bingofuel in forum C Programming
    Replies: 9
    Last Post: 03-06-2011, 05:30 AM
  2. Problem with Accessing Variables
    By vileoxidation in forum C++ Programming
    Replies: 10
    Last Post: 10-05-2009, 07:58 AM
  3. Variables problem
    By t014y in forum C Programming
    Replies: 8
    Last Post: 09-03-2008, 04:40 PM
  4. variables problem
    By zeeky in forum C++ Programming
    Replies: 15
    Last Post: 03-09-2006, 10:58 AM
  5. Problem with global variables
    By DominicTrix in forum C++ Programming
    Replies: 6
    Last Post: 09-08-2004, 01:26 PM

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