DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: catch char while user types (in C) ?

  1. #1
    Join Date
    Oct 2006
    Posts
    4

    Angry catch char while user types (in C) ?

    Some newbie help anyone, for "catching" the characters a user types and giving a menu selection when a "match" is detected. Here is a piece of PseudoCode:

    --------------------------------------------------
    printf //user types something
    scanf //catch user input

    if program detects e.g. first letter typed "w" : then
    program printf "menu": selection1, selection2;

    scanf : selection1 or selection2;
    else

    if no match of word(no selection) : then
    user continue typing

    program loops for the next char detection...
    --------------------------------------------------

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    It's possible to do something similar by replacing printf and scanf with getch, getche and getc. These three functions/macros are declared in stdio.h and conio.h. They differ with respect to whether they echo the input character on the screen,so you want to experiment with them and decide which one suits you best.
    Danny Kalev

  3. #3
    Join Date
    Jan 2005
    Posts
    49
    check out the functions in conio.h,
    NN

  4. #4
    Join Date
    Oct 2006
    Posts
    4

    Question A bit more revised code for "char text app"...Any help ?

    OK, a little bit of a more revised code, but still not functioning as it should :SICK: What should happen here is, the user enters a char, the entered char is compared with the first char in the "wordlist.txt" file and if there is a match the app should prompt the user for matching words found in the file and continue for the next char (using pointers only).

    Code:
    printf("Enter text: ");
            scanf("%s", &string);
    
            fnstrcpy (string, stringTemp);
    		FILE * inputFilePtr;
            char chFromFile;
            inputFilePtr = fopen ("wordlist.txt","r");
    		if (inputFilePtr==NULL) perror ("Error opening file");
                else
                {
                    do 
                    {
                        chFromFile = fgetc (inputFilePtr);
                        if (chFromFile == *stringTemp)
                         
                            printf("The chars match!");
                            else
                            {
                                printf("The chars NOT match!");
                            }
                        
                    } while (chFromFile != EOF);
                    fclose (inputFilePtr);
                }
            getch();
        }
    }
    /* 
      Function "fnstrcpy"
      Copy string "sourceChar" to "destinChar"
      Return a pointer to destination string
    */
    
    char *fnstrcpy(char *sourceChar, char *destinChar)
    {
    	while (*sourceChar++ = *destinChar++);
    	return destinChar;
    }

Similar Threads

  1. Replies: 0
    Last Post: 02-21-2006, 09:47 PM
  2. Senior User Experience Researcher San Jose
    By Branta in forum Careers
    Replies: 0
    Last Post: 02-13-2006, 08:45 PM
  3. Replies: 0
    Last Post: 07-20-2001, 06:02 AM
  4. Adding New NT User Account
    By John Whitney in forum VB Classic
    Replies: 2
    Last Post: 02-02-2001, 12:15 AM
  5. Flaw in C# ?
    By Gunnar Skogsholm in forum .NET
    Replies: 20
    Last Post: 01-17-2001, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center