Pointer help

This is a discussion on Pointer help within the C++ Programming forums, part of the General Programming Boards category; Hey guys I was trying to add a pointer to the code below to that it will also count ints ...

  1. #1
    182
    182 is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    Pointer help

    Hey guys I was trying to add a pointer to the code below to that it will also count ints that occur in one line in a text file for example if in one line there was:

    int j,l,k; int t; int p;.

    But my pointer is all wrong could someone point out where I went wrong?

    (I know this isnt the best way to do this using arrays but its the way I have to do it thanks.)

    Code:
    char * ch = array;
    char array [200];
    ifstream file;
    
    file.open(filel); 
    
    	if (file.is_open()) 
    
    	{
                 while (file.getline( array, sizeof(array) ))
    	          {
                           	if( ( ch=strstr ( array, "int " )) != 0 )
    			{
    				fint++;
                                 ch++
                              for (i =0; i <sizeof(array)  ; i++
    
                                if (array[i]==',')
                                     fint++
    				if (array[i]==';')
                                     break;
                               }
                 }

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Just at first glance:
    Code:
    char * ch = array;
    char array [200];
    You are assigning array to ch* before you declare array. Try switching the order of these lines.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    You know, there are about half a dozen live threads from you all covering basically the same problem.

    Not only is this annoying, it's also really hard to give you any kind of advice in a coherent manner. If you're also playing this board off against several other boards as well, that's a huge flood of conflicting information. You're not going to solve the problem like that at all.

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    What do you mean, Salem?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 04:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 08:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21