Thread: can u help me........with string

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    14

    Wink can u help me........with string

    hi..................
    i o this program but i cant find the error
    can u help me
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdlib.h>


    //Number search fucnction
    void searchnum(char *);
    //Converting function
    void convertdig(char *);


    void main()
    {

    char text[100];

    //Inputting the text and it's preconverting status
    printf("Please input a text with numbers(1-99) to be converted into words:\n");
    gets(text);
    printf("\n%s\n%s","The text before conversion is:",text);

    //Calling the searching function
    searchnum(text);

    }

    void searchnum(char *text)
    {
    char *token;
    //First call to tokenizing function
    token=strtok(text," ");
    printf("\n\nThe text after conversion is:\n");

    //Loop to find the position of the number to call the converting function
    while (token != NULL)
    {
    //If a digit is found
    if (isdigit(token[0]))
    convertdig(token);
    //If a digit is not found
    else
    printf("%s ",token);
    //To call the function to the end of the character string
    token = strtok(NULL, " ");
    }

    }

    void convertdig(char *text)
    {
    int num,num2;
    char *rem;
    num = strtol(text,&rem,0);

    char *chr1[]={"One","Two","Three","Four","Five","Six","Seven", "Eight","Nine"};
    char *chr2[]={"Eleven","Twelve","Thirteen","Forteen","Fifteen" ,"Sixteen","Seventeen","Eighteen","Nineteen"};
    char *chr3[]={"Ten","Twenty","Thirty","Fourty","Fifty","Sixty" ,"Seventy","Eighty","Ninety"};

    //Format of output number and range
    if (num < 10)
    printf("%s ",chr1[num-1]);
    else if (num >= 10 && num <20)
    printf("%s ",chr2[num-11]);
    else
    {
    num2=num%10;
    num=num/10;
    printf("%s %s ",chr3[num-1],chr1[num2-1]);
    }
    }
    show me the meaning

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    124
    >How many times do we have to tell you to use code tags?
    ..... and also about void main

    Anyway, the code you wrote works - if you type the right input.

    P.S: If you want to use strtol(), num should be of type long.
    Loading.....
    ( Trying to be a good C Programmer )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM