simple JPEG problem

This is a discussion on simple JPEG problem within the C Programming forums, part of the General Programming Boards category; Igot a simple problem that i've already asked about before but the answear i got didn't work. I want to ...

  1. #1
    Registered User the bassinvader's Avatar
    Join Date
    Jul 2006
    Location
    Europe
    Posts
    51

    simple JPEG problem

    Igot a simple problem that i've already asked about before
    but the answear i got didn't work. I want to open JPEG files
    in C and was told to open the file as usual but using binary
    like this;
    Code:
    #include<stdio.h>
    
    main()
    {
        
        FILE *ptr;
        
        ptr=fopen("c:\\test.jpeg","rb");
        
        if(ptr==0){
        printf("didnt work");
        getchar();}
        else
        fclose(ptr);
        
        return 0;
    }
    I know its real easy for you wiz's but i havent found anything
    that can answear my simple question!!

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    What didn't work? What error are you getting?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Add this to your code and see what you get:
    Code:
        if(ptr==0){
        printf("didnt work");
        perror("Error");
        getchar();}

  4. #4
    Registered User the bassinvader's Avatar
    Join Date
    Jul 2006
    Location
    Europe
    Posts
    51

    Unhappy

    ok

    so perror tells me "no such file or directory found" however at the same time i can see
    the image file there!!

    And the code works fine with a txt file in the same location. I dont see any reason for perror to tell me what its telling me!?!

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Are you absolutely sure the image file is in the root of C and called exactly what you have in the code? Is the image perhaps called test.jpg, and not .jpeg?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User the bassinvader's Avatar
    Join Date
    Jul 2006
    Location
    Europe
    Posts
    51
    thanks cornedBee.

    The extension was JPG and not JPEG.

    Another of my little problems solved.

    Thanks for the help guys. I owe you one:-)

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    It is for this reason I like to use this kind of skeleton.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       static const char filename[] = "c:\\test.jpeg";
       FILE *file = fopen( filename,  "r" );
       if (file != NULL)
       {
          /* do stuff */
          fclose( file );
       }
       else
       {
          perror( filename );
       }
       return 0;
    }
    
    /* my output
    c:\test.jpeg: No such file or directory
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 01:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 08:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM

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