Hello, I'm a newbie in C, but i'm trying to make a file to configurate/manipulate variables of a C code.
I tried using int and extern int throught a header or another C code but it doesn't seems to work (even throught the makefile). I also tried (with XML) to put a data structure to hold the shared variables with the XML_SetUserData function to pass a pointer to this structure to the handlers.
Maybe i did something wrong, but i can't find where. Any help is welcome. Thanks.
---------- Post updated at 04:46 PM ---------- Previous update was at 03:41 PM ----------
So,here is code.h
#ifndef _CODE_H
#define _CODE_H
#include <stdio.h>
#include <stdlib.h>
#define X 1
typedef unsigned char X_Bool;
#define X_TRUE ((X_Bool) 1)
#define X_FALSE ((X_Bool) 0)
#define X_MODE ((X_Bool) 2)
#endif
then conf.c
int M;
M = 2;
and then code.c
#include <stdio.h>
#include "code.h"
extern int X;
extern int M;
int main(int argc, char *argv[]) {
while (1) {
printf("\n%s\n", M);
printf("\n%s\n", X);
printf("\n%s\n", X_MODE);
}
and then the compile
gcc code.c conf.c -o decode `pkg-config --cflags --libs gstreamer-0.10
I want to change variable throught code.h or conf.c for code.c but it fail. It seems to ignore it with no errors.
The code you've given won't compile, missing brackets in places.
I don't know what your while-loop is for. That will just print the same things over and over.
The variable X won't work right, because X also exists as a #define, whenever you use X it will be turned into 1 by simple text replacement.
The variable M ought to properly show up as 2. What were you expecting it to do, and in what way was it not working?
I'm using Gstreamer, and i want to have the possibility to change parameters in my pipeline throught a configuration file.
Here is my pipeline:
str = g_strdup_printf (
"rtspsrc protocols=PTCP latency=LAT "
" timeout=TIMO buffer-mode=BUFM location=%s name=src"
" ! queue ! gstrtpbin latency=LATE name=srcbin "
" ! queue min-threshold-time=QUE ! rtph264depay ! ffdec_h264"
" ! interlace top-field-first=true field-pattern=FP"
" ! videoscale add-borders=true ! videorate"
" ! colorspace"
" ! video/x-raw-yuv,framerate=25/1,height=576,width=720,format=(fourcc)UYVY"
" ! decklinksink name=sink mode= mood "
" src. ! queue min-threshold-time=QMTT ! rtpmp4adepay ! aacparse ! faad ! audioconvert ! audioresample ! sink. sync=true"
,argv[1]);
pipeline = gst_parse_launch (str,NULL);
which i want to be able change PTCP, LAT, TIMO, BUFM, LATE, QUE, FP, mood, and the caps
An .h file is not a configuration file. It gets read when you run gcc, not when you run the program.
You could have a simple configuration file like this:
VAR1=VALUE1
VAR2=VALUE2
...
and use it like this:
char buf[512], var[512], val[512];
FILE *fp=fopen("/path/to/configfile", "r");
setenv("protocols", "PCTP"); // Set a default
while(fgets(buf, 512, fp) != NULL)
{
if(sscanf(buf, "%[^=]=%s", var, val) != 2) continue;
setenv(var, val);
}
fclose(fp);
str = g_strdup_printf (
"rtspsrc protocols=%s latency=LAT "
" timeout=TIMO buffer-mode=BUFM location=%s name=src"
" ! queue ! gstrtpbin latency=LATE name=srcbin "
" ! queue min-threshold-time=QUE ! rtph264depay ! ffdec_h264"
" ! interlace top-field-first=true field-pattern=FP"
" ! videoscale add-borders=true ! videorate"
" ! colorspace"
" ! video/x-raw-yuv,framerate=25/1,height=576,width=720,format=(fourcc)UYVY"
" ! decklinksink name=sink mode= mood "
" src. ! queue min-threshold-time=QMTT ! rtpmp4adepay ! aacparse ! faad ! audioconvert ! audioresample ! sink. sync=true"
,getenv("protocols"), argv[1]);
Thank you Corona ! I've got things to do, but i'll do it as soon as possible.
I have now done the code, and it work. Thanks again 