Thread: Need help with lack of basic coding

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    Need help with lack of basic coding

    Code:
    /* pupose: picking the character from the chunk of text, then analyst what type of that token is
    */
    
    
    #include <iostream>
    #include <cctype>
    #include <string>
    #include <cstdlib>
    
    
    using namespace std;
    const int max = 1000;
    int type(char block[],int pos); // type of the token
    void getword(char block[], char token[], int &pos);
    void getnumber(char block[], char token[], int &pos);
    void print(char token[],int type);
    void getpunc(char block[], char token[], int &pos);
    bool gettoken(char block[],char token[], int &type,int &pos);
    int main()
    {
        int type;
    
    
        int pos = 0;
       char block[1000]= "Writing code is extremely hard!";
    
    
       system("PAUSE");
          return 0;
    }
     int type(char block[],int pos)
     {
         if(isalpha(block[pos]))
         return 1; 
        if(isalnum(block[pos]))
            return 2;
        if(ispunct(block[pos]))
            return 3;
     }
    
    
        //Realize the word is the type 
    
    
    void getword(char block[], char token[], int &pos)
    {
         int i, type;
         while(isalpha(block[pos]))
             {
             token[i]=block[pos];
             i++;
             pos++;
             token[i] = '\0'; 
             }
         }                          
     //Realize the number is the type 
    void getnumber(char block[], char token[], int &pos)
    {
         int i,type;
         while(isalnum(block[pos]))
               {
                      block[pos]= token [i];
                       i++;
                       pos++;
                       token[i]='\0';
                   }
         
    }
     //Realize the punctuation is the type 
    void getpunc(char block[], char token[], int &pos)
    {
         int i, type;
         while(ispunct(block[pos]))
               {
                  block[pos] = token[i];
                  i++;
                  pos++;
                  token[i]='\0';
                                   
               }
         
    }
    
    
    bool gettoken(char block[],char token[], int &type,int &pos)
    {
         token[0] = block[pos];
         token[1] = '\0';
         type = 1;
         pos++;
         if ( pos >strlen(block)) return true;
         else return false;
     }
        void print(char token[],int type)
        {
             for(int i = 0; i < type; i++)
             cout<<token<<" "<<type<<endl;
             }
    Here is the process with very hard working but I don't know where am i getting wrong!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What is your question about the code posted? What is your program doing that is wrong? What do you expect your program to do? Does your program compile without errors? If not post the complete error messages exactly as they appear in your development environment.

    Jim

  3. #3
    Do you C what I C? jamesallen4u's Avatar
    Join Date
    Oct 2011
    Posts
    43
    You might want to look at line 91...
    Linux Distro: Ubuntu 12.04
    Browser: Chromium

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You may want to indent properly...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    I don't know why my program didn't run do I miss anything? because when I try to run them, it didn't work even without any syntax error!

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    "didn't work" is a very generic problem description and impossible to debug.
    1) Did you recompile and relink your executable?
    2) Any errors or warnings during the recompile?
    3) When you run your executable, what is the observed behavior versus the expected behavior?

    Edit: Also, by the way, your main() function doesn't do anything...
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very Basic Telnet/Mud Client - coding n00b
    By Cebb in forum C Programming
    Replies: 19
    Last Post: 10-11-2011, 04:16 PM
  2. Lack of variable declaration
    By ignis in forum C Programming
    Replies: 10
    Last Post: 01-27-2011, 09:07 AM
  3. Very basic C coding warning
    By Gikimish in forum C Programming
    Replies: 3
    Last Post: 10-02-2010, 06:06 AM
  4. Lack O' Inspiration
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 07-17-2005, 10:09 AM