Thread: Help and help!!!!!!!!!!!!!!!!!!!!!!!!

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    6

    Help, help me please!!!!!!!!!!!!!!!!!!!!!!!!

    I am trying to read each separate word in an input stream to each element in an array. Could somebody help me to point out why I can't print the WordArray out?
    Thanks!

    /* Task: put in each single word to single element in an
    * array and print out.
    * only alphanumeric characters are allowed.
    */
    Code:
     
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    
    /***********************Functions******************/
    void main (){
    	static char Array[30];
    	static char WordArray[30];
    	int iWord=0;
    	int iPrint;
    	int i=0; /* index for array digitArray */
    	char ch;
    
    
    	printf("Enter a text sentence: ");
    	ch= getchar();
    	while (ch != '\n' && isalpha(ch)) {
    		do {
    			Array[i] = ch;
    			i++;
    			ch = getchar();
    		}while(isalpha(ch));
    		Array[i] = '\0';
    
                             /*Each word is being placed in 1 element*/
    		strcpy(&WordArray[iWord],Array);
    		iWord++;
    		i = 0;
    
                              /* As long as there are more spaces than one 
    		while (ch == ' ') { 
    		     ch = getchar();
    		}
    		
                       if ((isalpha(ch))==0 && (isspace(ch))==0 && ch!= '\n')
    			fprintf(stderr,"This is an error.\n");
    		
    	}/*End while*/
    	
    	for (iPrint = 0; iPrint<iWord; iPrint++)
    	printf("%s\n", WordArray[iPrint]);
                  /* Why can't I print it out???????*/
    	
    }/*End Main*/
    Last edited by tuanvo; 01-12-2003 at 02:35 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Sorry, I don't know how to use CODE TAG
    Beginner.
    Well if you actually took a few seconds to read the sticky posts, you know the one, the one titled << !! Posting Code? Read this First !! >> you'd know how...

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

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    6

    Thanks Salem

    It works now thanks lot, Salem.

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> No - main returns an int

    You must get frustrated having to explain this to like, everybody. You need to hold a seminar named: "void main() == evil"

  5. #5
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    how about we flame each other again because of void main() and int main ()?


  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>how about we flame each other again because of void main() and int main ()?
    No, let's not.
    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