#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0

    Error: ‘itoa’ was not declared in this scope


    i tried to compile a source file using :

    g++ -O2 -Wall -o VideoToImages VideoToImages.cpp `pkg-config --cflags --libs opencv`


    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include "cv.h"
    #include <highgui.h>
    #include "cxcore.h" 
    int main( int argc, char** argv )
    {    
    
        CvCapture *capture = cvCaptureFromAVI("xyz.avi");
        if(!capture) 
        {
            printf("!!! cvCaptureFromAVI failed (file not found?)\n");
            return -1; 
        }
    
        int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
        printf("* FPS: %d\n", fps);
    
        IplImage* frame = NULL;
        int frame_number = 0;
        char key = 0;   
    
        while (key != 'q') 
        {
            // get frame 
            frame = cvQueryFrame(capture);       
            if (!frame) 
            {
                printf("!!! cvQueryFrame failed: no frame\n");
                break;
            }       
    
            char filename[100];
            strcpy(filename, "frameSplit");
    
            char frame_id[30];
            itoa(frame_number, frame_id, 10);
            strcat(filename, frame_id);
            strcat(filename, ".png");
    
            printf("* Saving: %s\n", filename);
    
            if (!cvSaveImage(filename, frame,0))
            {
                printf("!!! cvSaveImage failed\n");
                break;
            }
    
            frame_number++;
    
            // quit when user press 'q'
            key = cvWaitKey(1000 / fps);
        }
    
        // free resources
        cvReleaseCapture(&capture);
    
        return 0;
    }
    but i got this error

    VideoToImages.cpp: In function ‘int main(int, char**)’:
    VideoToImages.cpp:38:40: error: ‘itoa’ was not declared in this scope
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    itoa() is a non-standard function. Use sprintf() or snprintf() instead of itoa().
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by Scorpions4ever
    itoa() is a non-standard function. Use sprintf() or snprintf() instead of itoa().
    when i changed
    itoa(frame_number, frame_id, 10);
    with

    sprintf(frame_number, frame_id, 10);
    or
    snprintf(frame_number, frame_id, 10);

    i still have problems
    maybe i didn't use it properly !!
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    Well you certainly didn't go and read the manual pages before trying it.

    Code:
        int frame_number = 0;
    ...
            char frame_id[30];
            itoa(frame_number, frame_id, 10);
    So you just replaced the function name without having a clue.
    sprintf(frame_number, frame_id, 10);

    int sprintf(char *str, const char *format, ...);
    Now try something like this
    sprintf(frame_id,"%d",frame_number);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by salem
    Well you certainly didn't go and read the manual pages before trying it.

    Code:
        int frame_number = 0;
    ...
            char frame_id[30];
            itoa(frame_number, frame_id, 10);
    So you just replaced the function name without having a clue.
    sprintf(frame_number, frame_id, 10);

    int sprintf(char *str, const char *format, ...);
    Now try something like this
    sprintf(frame_id,"%d",frame_number);

    it work fine but i still have another error
    "failed: no frame"
  10. #6
  11. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    GetErrStatus
    And look up cvErrorStr as well.

    Then perhaps you'll be able to figure out something better than "it didn't work" as an error report.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo