Thread: Strings

  1. #1
    Unregistered
    Guest

    Strings

    I need help in writing a program that asks a user to input a letter to see if the letter inputed is in the program. Then if it is true the program returns the position of where the text is located. If it is false then it says no match found. Then i have to error check to see that the input was really a character.

    MY CODE SO FAR
    #include<stdio.h>

    int found_number(int a[], int, int);
    void getch(int array[], int, int);
    int main()
    {
    int char[] = { "Hello World"};

    if( found_number( char, 9, 4))
    printf("Found It!\n");
    else
    printf("No Such Luck...\n");

    getch(char, 9, 4);
    }
    return 0;
    }
    void getch(int array[], int count, int search)
    {
    int i;
    for (i = 0; i < count; i++)
    {
    if (array[i]== search)
    break;
    }
    if (i==count)
    printf('\n %d was not found in Array", search);
    else
    printf ("\n%d was not found in slot %d", search, i);
    }

    PLEASE HELP

    return 0;
    }
    int found_number(int array[], int count, int search)
    {
    int i;
    for (i = 0; i < count; i++)
    {
    if (array[i] == search)
    printf("Found it");
    else
    printf("Match Not Found");
    }
    return 0;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And your question is........

    A couple of pointers:

    >getch()
    is a function provided by some compiler that allows you to pause the program and wait for a key press. I doubt you are expected to write your own version.

    There are some problems with misplaced }'s.

    >int char[] = { "Hello World"};
    char is a reserved keyword, you cannot create a variable with the same name.
    Why are you creating an int array, and storing chars in it?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM