anithmetic

This is a discussion on anithmetic within the C++ Programming forums, part of the General Programming Boards category; which way is the better way ? i get this error with this line 34 C:\.....cpp [Warning] NULL used in ...

  1. #1
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638

    anithmetic

    which way is the better way ?

    i get this error with this line

    34 C:\.....cpp [Warning] NULL used in arithmetic
    Code:
    	 while(line[buf] != NULL){ cout << line[buf]; buf++; }
    it still compiles but just gets stuck doing nothing. would
    Code:
     while(line[buf] !=  "" ){ cout << line[buf]; buf++; }
    
    or
    
     while(line[buf] !=  0  ){ cout << line[buf]; buf++; }
    be better ? or something else ? thank you.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    681
    What do you want to check? Whether line[buf] contains ANY string, or whether the string it contains is empty?
    Code:
    while(line[buf] != NULL){ cout << line[buf]; buf++; }
    Checks whether it contains any string.

    Code:
    while(line[buf] !=  "" ){ cout << line[buf]; buf++; }
    Wrong in both cases.

    Code:
    while(line[buf] !=  0  ){ cout << line[buf]; buf++; }
    Same as the first one.
    I never put signature, but I decided to make an exception.

  3. #3
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    Code:
      while (!in.eof())
    	   {
    		  getline (in, line);
    		  meta = line.find("meta");
    		  if(meta >= 0)
    		  {
    			 cout << "\nmeta == " << fileline << "\n" << endl;
    			
    			 name = line.find("data");
    			 buf = name + 12;
    			 cout << "meta: ";
    			 while(line[buf] != NULL){ cout << line[buf]; buf++; }
    			 cout << endl;

    both ? how about the end of the tag data ?

    prog looks for "meta" tag data inside a file. reads data in to variable and puts that out to the screen. problem is finding end of tag data. there are several strings as far as i can tell. then more of the file. want to read all the strings in the right variable. thinking that this could be redone as a structure and then filled. i need to do some more reading on tags and see if i can find the one this file uses. then i should have some reference as to how long each string is.

    figured out why it just sits there doing nothing. there was no "meta" tag in side the file. i opened the file with notepad. there were other tags in there. as i said i need to find the info on which tag this file uses. thank you for the reply and it helped me realize that i was missing the info i needed to do the program.

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    1. From where the variable fileline is accessed? (As i can't see through your whole code, anyways let i suppose it's initialized or set somewhere.)
    2. Okay, let take a case.
    e.g. Your line array contains: "My meta found a huge data"
    When you first find meta, it should return 3 and within loop when you find data it should return 21, and you add 12 in it which makes buf as 33 and your string is of length less than 33.
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    You should check if the second find actually succeeds.
    Furthermore, it is bad to use eof as loop control. There IS a faq about that on the site.
    And finally, I have no idea what this piece is supposed to do:
    Code:
    while(line[buf] != NULL){ cout << line[buf]; buf++; }
    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.

  6. #6
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    i did not write the original program. i only tried to modify it to do what i wanted. thank you for the suggestions. i am going to read through the faq again. that line i thought reads in the tag line and puts it in the buffer and then increments the count. guess not. going to restart. first when i find the info on the wright tag then i will apply that.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    We cannot see how "line" is declared.
    And the...
    line[buf] != NULL
    ...looks suspicious.
    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.

  8. #8
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    it is defined as a string. as i said i am going to start over with this project. i just needed something quick to check the tags.

    [code ]
    string line;
    [/code]

  9. #9
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    TIFF Tag Reference, EXIF Tags

    ok here is the redo. this is what i have so far. some work on the structure is yet needed.

    Code:
    /* metatagreadertwo0001.cpp */
    
    #include <windows>
    #include <fstream>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main() {
        
        struct camm {
                      ExposureTime
                      FNumber
                      ExposureProgram
                      SpectralSensitivity
                      ISOSpeedRatings
                      OECF
                      ExifVersion
                      DateTimeOriginal
                      DateTimeDigitized
                      ComponentsConfiguration
                      CompressedBitsPerPixel
                      ShutterSpeedValue
                      ApertureValue
                      BrightnessValue
                      ExposureBiasValue
                      MaxApertureValue
                      SubjectDistance
                      MeteringMode
                      LightSource
                      Flash
                      FocalLength
                      SubjectArea
                      MakerNote
                      UserComment
                      SubsecTime
                      SubsecTimeOriginal
                      SubsecTimeDigitized
                      FlashpixVersion
                      ColorSpace
                      PixelXDimension
                      PixelYDimension
                      RelatedSoundFile
                      FlashEnergy
                      SpatialFrequencyResponse
                      FocalPlaneXResolution
                      FocalPlaneYResolution
                      FocalPlaneResolutionUnit
                      SubjectLocation
                      ExposureIndex
                      SensingMethod
                      FileSource
                      SceneType
                      CFAPattern
                      CustomRendered
                      ExposureMode
                      WhiteBalance
                      DigitalZoomRatio
                      FocalLengthIn35mmFilm
                      SceneCaptureType
                      GainControl
                      Contrast
                      Saturation
                      Sharpness
                      DeviceSettingDescription
                      SubjectDistanceRange
                      ImageUniqueID
                      } 
                      
                      
                      
                      
                      
                      
        
        int count;
        string buff[256];
       
       ifstream in( "CDSC000032.jpg" );
       
        string s;
      while(getline(in, s)) // Discards newline char
        out << s << "\n"; // .... must add it back
    }

Popular pages Recent additions subscribe to a feed

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