Thread: Comparing string arrays

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'll post an example in an edit to this post.

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    #define SIZE 100
    
    int main() {
      int i, n;
      char s[SIZE]="";
      char ch;
      printf("\n\nEnter some letters and numbers, and etc. Only letters will go into the array s[]\n");
      i=0;
      while((ch=getc(stdin)) != EOF) { //EOF is Ctrl+Z
        if(isalpha(ch)) {
          s[i++]=ch;
        }
      }
    
      printf("\n%s", s);
    
      printf("\n\n\t\t\t     press enter when ready");
      (void) getchar(); 
      return 0;
    }
    variable++ increments the variable by one.

    Yes, you should use a char array.
    Last edited by Adak; 03-20-2011 at 12:15 AM.

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    27
    In your code, how do I enter after I type something? Pressing enter only goes to a new line.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Adak View Post
    I'll post an example in an edit to this post.
    Code:
      char ch;
      printf("\n\nEnter some letters and numbers, and etc. Only letters will go into the array s[]\n");
      i=0;
      while((ch=getc(stdin)) != EOF) { //EOF is Ctrl+Z
    The value EOF cannot be stored in a char. It is a negative integer type, that holds no char representable value.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  2. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 08:01 PM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  4. string arrays
    By Raison in forum C Programming
    Replies: 27
    Last Post: 10-02-2003, 06:27 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM