difference between scanf and fgets with OpenCV
Hi all,
I am writing an image filter in C and OpenCV but I notice that scanf and fgets produce different program's behaviours. In fact, if I write: Code:
#include <stdio.h> Code:
#include <stdio.h> Code:
#include <stdio.h> Code:
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /opt/local/var/macports, build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.11/modules/core/src/array.cpp, line 1238 Does anyone know what is the difference in "name" when I use scanf or by command line and when I use fgets instead? thanks in advance |
Hi
fgets include the \n character in the name string. Also, you should probably check that the file exists and give a better error message. |
Yes, it is true.
I modified the code as follows but I have a segmentation fault: Code:
#include <stdio.h> |
Hi
Yes, you don't allocate any memory for image before you use it. But why copy it? You could remove the last \n with something like this: Code:
size_t len = strlen(name); |
fgets returns the number of characters read, it looks like your use of it is incorrect.
consider this Code:
# define MAX_STR_LEN 50 |
All times are GMT -5. The time now is 12:45 PM. |