Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3945882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:04:03+00:00 2026-05-20T01:04:03+00:00

I realise that this question has been asked before. I’ve read the answers and

  • 0

I realise that this question has been asked before. I’ve read the answers and tried the solution but it hasn’t solved it for me.

I’m using OpenCV 2.1 in Ubuntu 10.10(32-bit) and Eclipse C IDE.

My Problem:

If i read a text line from a file, and store it in a char* variable and pass this to cvLoadImage, I get nothing. the text line i read from the file is a fully defined file path to a certain image.

here’s the code:

FILE *f = fopen("./input.txt","r");
char img1[50];
fgets(img1,50,f);
char* img3 = strtok(img1,"\n");
IplImage* frame = cvLoadImage(img3);

the result is that frame is now 0x00000000 and no picture

BUT

If I pass the same text as a argument to the executable, i can store argv[1] into a char* and pass that to cvLoadImage() and it reads the image as expected.

here’s the code:

char* img3 = argv[1];
IplImage* frame = cvLoadImage(img3);

I’m not sure what the cause of this is. :s

the string passed as argument and in file is exactly: (including quotes)
"/home/atharva/Documents/FYP/1a.jpg"

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:04:04+00:00Added an answer on May 20, 2026 at 1:04 am

    You need to remove the quotes from the string in the file. The quotes are only needed for the shell’s parser to get the path properly into the program’s argv list in the first place — and even then only really necessary if the file path has embedded spaces.

    Since fgets() reads an entire line of text (up to the \n), there’s no need to quote anything (although 50 chars isn’t much for a file path — you might want to increase that buffer size). And if it must be quoted in the file for some reason, then you need to remove them before passing it on to cvLoadImage().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise this question has been asked before however the previous answers have gotten
I realize that this question has been asked before - but none of the
I realise that this question has probably been asked to death, but none of
I realise this question has been asked many times before and I've tried pretty
I realize that this type of question has been asked several times before but
I realize that this question has been asked 100times but none that I have
While I realize that this question has been asked once or twice ago but
I realize that this question has been asked and has been answered here but
I know this question has been asked before, but none of the existing SO
I realise this question has been asking before, but I've yet to find an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.