Thread: Problem starting a homework problem for class. Please help!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    This is a sample where you can just read it in as a char string using correct functions. Also it filters out the numbers even if the string also contains some non-numeric characters.
    Code:
    #include <stdio.h>
    int main(){
    	char buffer[256];
    	fgets(buffer,255,stdin);
    	int i;
    	for(i=0;buffer[i]!='\0';i++){
    		switch(buffer[i]) {
    			case '0': printf("zero "); break;
    			case '1': printf("one "); break;
    			case '2': printf("two "); break;
    			case '3': printf("three "); break;
    			case '4': printf("four "); break;
    			case '5': printf("five "); break;
    			case '6': printf("six "); break;
    			case '7': printf("seven "); break;
    			case '8': printf("eight "); break;
    			case '9': printf("nine "); break;
    		} 
    	}
    	fgets(buffer,255,stdin);
    }
    Read about scanf:
    http://www.gidnetwork.com/b-59.html
    http://www.gidnetwork.com/b-62.html
    http://www.gidnetwork.com/b-63.html
    http://www.gidnetwork.com/b-64.html
    Last edited by maxorator; 10-09-2006 at 06:38 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Me with this homework problem Please!!
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2002, 07:54 PM
  2. C Homework Problem
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 03:43 AM
  3. Homework problem
    By bacon in forum C Programming
    Replies: 1
    Last Post: 04-24-2002, 07:21 AM
  4. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM
  5. homework assignment problem
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 10-29-2001, 10:24 AM