Thread: checking if an element is in a list

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

    checking if an element is in a list

    Hello, I am very new in C programming and here is my question
    I need to know how to program the following problem.

    read a list
    check if a specific element is included in it
    execute a function if the element is there

    i guess it goes something like this.

    get_list .......1
    for(i = 0; i < number-of-list-elements ; i++) .......2
    if( list[i] = specific-element) ........3
    execute function; ........4

    my problem is in the 3rd line, dont know how to C-scrpit it.
    thanx in advance for help

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    All the details, make all the difference!

    1) Is the list in a file? If so, what's the file name and path (if needed).
    2) What is the type of data in the list? Strings are handled a bit different than integers, etc.
    3) ditto, "specific-element". What's it's data type?

    Calling a function is just naming the function on it's own line, with the right parameters (if any), enclosed in parenthesis myFunction(); Functions need a prototype before they're referred to in the program. Something like this:

    Code:
    void myFunction(int number, char aLetter);
    This prototype shows myFunction has no return value from it (void), and will be passed one integer variable called "number", and one char variable called "aLetter").

    Welcome to the forums, and please give this a shot. Any program code you post here, click on the # sign after you highlight it, and it will put your code into "tags" to make it more readable.

    Please remember to indent your code three spaces or so, for each level of indentation.

    If you're confused about it, just look around at the posted code on the forum. Some is great, some is very hard to read.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. Pleas take a look & give a critique
    By sh3rpa in forum C++ Programming
    Replies: 14
    Last Post: 10-19-2007, 10:01 PM
  3. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  4. Segfault when removing element from list
    By jmd15 in forum C++ Programming
    Replies: 4
    Last Post: 04-05-2007, 12:25 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM