Thread: Cant find the syntax error....and clarification on what my program is doing.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    18

    Cant find the syntax error....and clarification on what my program is doing.

    gcc says: In function 'main':
    error: syntax error before "int"
    error: syntax error before "char"

    Code:
    #include <stdio.h>
    
    int main(){
        int i;
        
        char char_array[5] = {'a', 'b', 'c', 'd', 'e'};
        int int_array[5] = {1,2,3,4,5};
        
        char *char_pointer;
        int *int_pointer;
        
        char_pointer = (char*) int_array; /*typecast into the pointers data type*/
        int_pointer = (int*) char_array;
        
        for(i=0; i < 5; i++){
            printf("[integer pointer] points to %p, which is contains the
            char '%c'\n", int_pointer, *int_pointer);
        int_pointer = (*int) ((char*)int_pointer + 1);
        }
        
        for(i=0; i < 5; i++){
            printf("[char pointer] points to %p, which contains the int %d\n",
            char_pointer, *char_pointer);
        char_pointer = (*char) ((int*)char_pointer + 1);
        }
    }
    i am following a book and the books doesnt really explain: char_pointer = (*char) ((int*)char_pointer + 1);
    i would like to know what that piece of code is doing. also because ive already typecast in the beginning. so i dont see why its repeated.

    EDIT: I also dont understand the argument. isnt typecasting supposed to have this format: (typecast_data) variable ? so wouldnt it be just ((int*) char_pointer+1); ?
    Last edited by prafiate; 06-11-2012 at 04:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I cannot find out the error in the program.
    By from_china in forum C Programming
    Replies: 9
    Last Post: 06-19-2011, 12:11 AM
  2. Clarification for a complicated syntax
    By manasij7479 in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2011, 12:37 PM
  3. can't find error(s) in my program..help?
    By jennyt in forum C Programming
    Replies: 1
    Last Post: 11-23-2010, 08:11 PM
  4. syntax error for another program.
    By nesagsar in forum C++ Programming
    Replies: 19
    Last Post: 12-14-2006, 04:07 PM
  5. Need Help to Find the Error in this program
    By sangken in forum C Programming
    Replies: 7
    Last Post: 10-03-2006, 06:12 PM

Tags for this Thread