Search Results

Search found 916 results on 37 pages for 'stdio'.

Page 11/37 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • How does dereferencing of a function pointer happen?

    - by eSKay
    Why and how does dereferencing a function pointer just "do nothing"? This is what I am talking about: #include<stdio.h> void hello() { printf("hello"); } int main(void) { (*****hello)(); } From a comment over here: function pointers dereference just fine, but the resulting function designator will be immediately converted back to a function pointer And from an answer here: Dereferencing (in way you think) a function's pointer means: accessing a CODE memory as it would be a DATA memory. Function pointer isn't suppose to be dereferenced in that way. Instead, it is called. I would use a name "dereference" side by side with "call". It's OK. Anyway: C is designed in such a way that both function name identifier as well as variable holding function's pointer mean the same: address to CODE memory. And it allows to jump to that memory by using call () syntax either on an identifier or variable. How exactly does dereferencing of a function pointer work?

    Read the article

  • snprintf and Visual Studio 2010

    - by Andrew
    I'm unfortunate enough to be stuck using VS 2010 for a project, and noticed the following code still doesn't build using the non-standards compliant compiler: #include <stdio.h> #include <stdlib.h> int main (void) { char buffer[512]; snprintf(buffer, sizeof(buffer), "SomeString"); return 0; } (fails compilation with the error: C3861: 'snprintf': identifier not found) I remember this being the case way back with VS 2005 and am shocked to see it still hasn't been fixed. Does any one know if Microsoft has any plans to move their standard C libraries into the year 2010?

    Read the article

  • problem with the programme!!

    - by hopefulLLl
    kindly tell me what is the pblm with this function wont it help me find the sum of digits of a number?? #include<stdio.h> #include(math.h) void main() { int a,i=0,j=10,k,n=0,m; scanf("%d",&a); while((a%j!=0)&&i>=0) { m=pow(10,(i+1)); k=a%m; n=(a-(k*m)-n)/(m/10)+n; j=m*10; i++; } n=n+(n/(m/10)); printf("%d",n); } i know the parenthesis used with math.h are nt right..what else is the pblm..i need to use just while loop..or the for loop!

    Read the article

  • Include headers in header file?

    - by Mohit Deshpande
    I have several libraries made by myself (a geometry library, a linked list library, etc). I want to make a header file to include them all in one lib.h. Could I do something like this: #ifndef LIB_H_ #define LIB_H_ #include <stdio.h> #include <stdlib.h> #include <linkedlist.h> #include <geometry.h> .... #endif Then I could just reference this one library and actually reference multiple libraries. Is this possible? If not, is there a way around it?

    Read the article

  • SWIG & C/C++ Python API connected - SEGFAULT

    - by user289637
    Hello, my task is to create dual program. At the beginning I start C program that calls throught C/C++ API of Python some Python method. The called method after that call a function that is created with SWIG. I show you my sample also with backtrace from gdb after I am given Segmentation fault. main.c: #include <Python.h> #include <stdio.h> #include "utils.h" int main(int argc, char** argv) { printf("Calling from C !\n"); increment(); int i; for(i = 0; i < 11; ++i) { Py_Initialize(); PyObject *pname = PyString_FromString("py_function"); PyObject *module = PyImport_Import(pname); PyObject *dict = PyModule_GetDict(module); PyObject *func = PyDict_GetItemString(dict, "ink"); PyObject_CallObject(func, NULL); Py_DECREF(module); Py_DECREF(pname); printf("\tbefore finalize\n"); Py_Finalize(); printf("\tafter finalize\n"); } return 0; } utils.c #include <stdio.h> #include "utils.h" void increment(void) { printf("Incremention counter to: %u\n", ++counter); } py_function.py #!/usr/bin/python2.6 '''py_function.py - Python source designed to demonstrate the use of python embedding''' import utils def ink(): print 'I am gonna increment !' utils.increment() and last think is my Makefile & SWIG configure file Makefile: CC=gcc CFLAGS=-c -g -Wall -std=c99 all: main main: main.o utils.o utils_wrap.o $(CC) main.o utils.o -lpython2.6 -o sample swig -Wall -python -o utils_wrap.c utils.i $(CC) utils.o utils_wrap.o -shared -o _utils.so main.o: main.c $(CC) $(CFLAGS) main.c -I/usr/include/python2.6 -o main.o utils.o: utils.c utils.h $(CC) $(CFLAGS) -fPIC utils.c -o $@ utils_wrap.o: utils_wrap.c $(CC) -c -fPIC utils_wrap.c -I/usr/include/python2.6 -o $@ clean: rm -rf *.o The program is called by ./main and there is output: (gdb) run Starting program: /home/marxin/Programming/python2/sample [Thread debugging using libthread_db enabled] Calling from C ! Incremention counter to: 1 I am gonna increment ! Incremention counter to: 2 before finalize after finalize I am gonna increment ! Incremention counter to: 3 before finalize after finalize I am gonna increment ! Incremention counter to: 4 before finalize after finalize Program received signal SIGSEGV, Segmentation fault. 0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.6.so.1.0 Backtrace: (gdb) backtrace #0 0xb7ed3e4e in PyObject_Malloc () from /usr/lib/libpython2.6.so.1.0 #1 0xb7ca2b2c in ?? () #2 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0 #3 0xb7eb014c in ?? () from /usr/lib/libpython2.6.so.1.0 #4 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #5 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0 #6 0x00000001 in ?? () #7 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0 #8 0xb7f4f014 in _PyObject_GC_Malloc () from /usr/lib/libpython2.6.so.1.0 #9 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0 #10 0xb7f4f104 in _PyObject_GC_NewVar () from /usr/lib/libpython2.6.so.1.0 #11 0xb7ee8760 in _PyType_Lookup () from /usr/lib/libpython2.6.so.1.0 #12 0xb7f99820 in ?? () from /usr/lib/libpython2.6.so.1.0 #13 0x00000001 in ?? () #14 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0 #15 0xb7ef13ed in ?? () from /usr/lib/libpython2.6.so.1.0 #16 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #17 0x00000001 in ?? () #18 0xbfff0c34 in ?? () #19 0xb7e993c3 in ?? () from /usr/lib/libpython2.6.so.1.0 #20 0x00000001 in ?? () #21 0xbfff0c70 in ?? () #22 0xb7f99da0 in ?? () from /usr/lib/libpython2.6.so.1.0 #23 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #24 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #25 0x080a6b0c in ?? () #26 0x080a6b0c in ?? () #27 0xb7e99420 in PyObject_CallFunctionObjArgs () from /usr/lib/libpython2.6.so.1.0 #28 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #29 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #30 0x800e55eb in ?? () #31 0x080a6b0c in ?? () #32 0xb7e9958c in PyObject_IsSubclass () from /usr/lib/libpython2.6.so.1.0 #33 0xb7f8dd40 in ?? () from /usr/lib/libpython2.6.so.1.0 #34 0x080a9020 in ?? () #35 0xb7fb78f0 in PyFPE_counter () from /usr/lib/libpython2.6.so.1.0 #36 0xb7f86ff4 in ?? () from /usr/lib/libpython2.6.so.1.0 #37 0x00000000 in ?? () Thanks for your help and advices, marxin

    Read the article

  • Why do i get segfault at the end of the application after everything's been done properly ?

    - by VaioIsBorn
    #include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char pass[] = "m4ak47"; printf("Vnesi password: \t"); scanf("%s", stole); if(strncmp(stole, pass, sizeof(pass)) != 0) { printf("wrong password!\n"); exit(0); } else printf("Password correct\n"); printf("some stuf here...\n\n"); return 0; } This program is working nice, but with one problem - if the password is correct then it DOES do the printing of 'some stuf here...' but it also shows me segmentation fault error at the end. Why ?

    Read the article

  • Why freed struct in C still has data?

    - by kliketa
    When I run this code: #include <stdio.h> typedef struct _Food { char name [128]; } Food; int main (int argc, char **argv) { Food *food; food = (Food*) malloc (sizeof (Food)); snprintf (food->name, 128, "%s", "Corn"); free (food); printf ("%d\n", sizeof *food); printf ("%s\n", food->name); } I still get 128 Corn although I have freed food. Why is this? Is memory really freed?

    Read the article

  • C: Incompatible types?

    - by Airjoe
    #include <stdlib.h> #include <stdio.h> struct foo{ int id; char *bar; char *baz[6]; }; int main(int argc, char **argv){ struct foo f; f.id=1; char *qux[6]; f.bar=argv[0]; f.baz=qux; // Marked line return 1; } This is just some test code so ignore that qux doesn't actually have anything useful in it. I'm getting an error on the marked line, incompatible types when assigning to type ‘char *[6]’ from type ‘char **’ but both of the variables are defined as char *[6] in the code. Any insight?

    Read the article

  • dose not name a type error in c++

    - by user985316
    #include <math.h> #include <stdlib.h> #include <stdio.h> #include <vector> #define IE 40 #define JE 40 #define KE 40 #define ia 7 #define ja 7 #define ka 7 #define NFREQS 3 using namespace std; main() float l,m,n,i,j,k,ic,jc,kc,nsteps,n_pml; float ddx,dt,T,epsz,muz,pi,eaf,npml; int ib,jb,kb; . . . . ic=IE*0.5 ; jc=JE*0.5 ; ....'ic'dose not name a type. ....'jc'dose not name a type.

    Read the article

  • When should an array name be treated as a pointer and when does it just represent the array itself? [duplicate]

    - by user1087373
    This question already has an answer here: When is an array name or a function name 'converted' into a pointer ? (in C) 4 answers I just made a test program after reading the book and the result turned out confusing: #include <stdio.h> int main(void) { char text[] = "hello!"; printf("sizeof(text):%d sizeof(text+2):%d sizeof(text[0]):%d \n",(int)sizeof(text), sizeof(text+2), sizeof(text[0])); printf("text:%p sizeof(text):%d &text:%p sizeof(&text):%d \n",text, sizeof(text), &text, sizeof(&text)); printf("text+1:%p &text+1:%p \n", text+1, &text+1); return 0; } The result: sizeof(text):7 sizeof(text+2):4 sizeof(text[0]):1 text:0xbfc8769d sizeof(text):7 &text:0xbfc8769d sizeof(&text):4 text+1:0xbfc8769e &text+1:0xbfc876a4 What makes me feel confused are: why the value of 'sizeof(text)' is 7 whereas 'sizeof(text+2)' is 4 what's the difference between 'text' and '&text'?

    Read the article

  • Can this example be done with pointers instead of global variable?

    - by Louise
    This is a simplified example of the problem I have: #include <stdio.h> #include <stdlib.h> void f2(int** a) { printf("a: %i\n", **a); } void f1(int* a) { f2(&a); } int main() { int a = 3; f1(&a); // prints "a: 3" f2(???); return 0; } The problem is that I would like to be able to use f2() both in main() and in f1(). Can that be done without using global variables?

    Read the article

  • Behavior with primitive data types' value out of range & C99's PRI* macros

    - by Yktula
    Say we have an 8-bit unsigned integer n (UINT8_MAX=255); what is the behavior of the compiler for n=256? Where can I find a table of default behavior when the value of a data type is out of range for different data types? Is there a pattern to how they behave when set out of range? #include <stdio.h> #include <inttypes.h> uint8_t n = UINT8_MAX; int main() { printf("%hhu ",n++); printf("%hhu",n); return 0; } Compiling with gcc -std=c99 -Wall *.c, this prints: 255 0 Also, is it acceptable to use C99's PRI* macros? How are they named?

    Read the article

  • How does this iterative Tower of Hanoi work? C

    - by Nitesh Panchal
    Hello, while surfing google, i found this interesting solution to Tower Of Hanoi which doesn't even use stack. Can anybody explain me in brief, what is it actually doing? And this solution really acceptable? #include <stdio.h> #include <stdlib.h> int main() { int n, x; printf( "How many disks? " ); scanf( "%d", &n ); printf("\n"); for (x=1; x < (1 << n); x++) printf( "move from tower %i to tower %i.\n", (x&x-1)%3, ((x|x-1)+1)%3 ); return 0; }

    Read the article

  • Linux c++ error: undefined reference to 'dlopen'

    - by lerax
    Hi all! I work in Linux with c++ (eclipse) and want to use a library. Eclipse shows me an error: undefined reference to 'dlopen' Do you know a solution? Here is my code. #include <stdlib.h> #include <stdio.h> #include <dlfcn.h> int main(int argc, char **argv) { void *handle; double (*desk)(char*); char *error; handle = dlopen ("/lib/CEDD_LIB.so.6", RTLD_LAZY); if (!handle) { fputs (dlerror(), stderr); exit(1); } desk= dlsym(handle, "Apply"); if ((error = dlerror()) != NULL) { fputs(error, stderr); exit(1); } dlclose(handle); }

    Read the article

  • C: switch case with logical operator

    - by Er Avinash Singh
    While I am new to c and want help in this program my code is : #include<stdio.h> #include<conio.h> void main(){ int suite=2; switch(suite) { case 1||2: printf("hi"); case 3: printf("byee"); default: printf("hello"); } printf("I thought somebody"); getche(); } I am working in turbo c and it shows no error and the output is helloI thought somebody Please, let me know how is this working ??? note :- here break is not the case as I intentionally left them.

    Read the article

  • Lua - initializing

    - by Ockonal
    Hello, I can't init lua correctly under Arch Linux. Lua - latest version. Here is my code: #include <stdio.h> extern "C" { #include <lua.h> #include <lauxlib.h> #include <lualib.h> } int main() { lua_State *luaVM = luaL_newstate(); if (luaVM == NULL) { printf("Error initializing lua!\n"); return -1; } luaL_openlibs(luaVM); lua_close(luaVM); return 0; } /tmp/cc0iJ6lW.o: In function main': test_lua.cpp:(.text+0xa): undefined reference toluaL_newstate' test_lua.cpp:(.text+0x34): undefined reference to `luaL_openlibs' test_lua.cpp:(.text+0x40): undefined reference to `lua_close' collect2: ld returned 1 exit status What's wrong?

    Read the article

  • Strange behaviour with fputs and a loop.

    - by Jonathan
    When running the following code I get no output but I cannot work out why. # include <stdio.h> int main() { fputs("hello", stdout); while (1); return 0; } Without the while loop it works perfectly but as soon as I add it in I get no output. Surely it should output before starting the loop? Is it just on my system? Do I have to flush some sort of buffer or something? Thanks in advance.

    Read the article

  • About This Code

    - by the-ifl
    Hi Guys , well I have a simple and a stupid question !! in this code what is the role of the symbol "%3d"...I Now That % mean refer To Variable ...... This is The Code : #include <stdio.h> int main(void) { int t, i, num[3][4]; for(t=0; t<3; ++t) for(i=0; i<4; ++i) num[t][i] = (t*4)+i+1; /* now print them out */ for(t=0; t<3; ++t) { for(i=0; i<4; ++i) printf("%3d ", num[t][i]); printf("\n"); } return 0; }

    Read the article

  • Problem overridding virtual function

    - by William
    Okay, I'm writing a game that has a vector of a pairent class (enemy) that s going to be filled with children classes (goomba, koopa, boss1) and I need to make it so when I call update it calls the childclasses respective update. I have managed to create a example of my problem. #include <stdio.h> class A{ public: virtual void print(){printf("Hello from A");} }; class B : public A{ public: void print(){printf("Hello from B");} }; int main(){ A ab = B(); ab.print(); while(true){} } Output wanted: "Hello from B" Output got: "Hello from A" How do I get it to call B's print function?

    Read the article

  • Why the output for "a" is -80?

    - by Abhi
    #include<stdio.h> #include<conio.h> #define ABC 20 #define XYZ 10 #define XXX ABC - XYZ void main() { int a; a = XXX * 10; printf("\n %d \n", a); getch(); } I thought the output should be 100 but when i saw the result i found o/p as -80. when i put bracket as #define XXX (ABC-XYZ) then i get output as 100 but without bracket i get o/p as -80.

    Read the article

  • WinMain not called before main (C/C++ Program Entry Point Issue)

    - by BT
    I was under the impression that this code #include <windows.h> #include <stdio.h> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { printf("WinMain\n"); return 0; } int main() { printf("main\n"); return 0; } would output WinMain, but of course nothing ever works how you expects. Anyways, could somebody please tell me how to get this program to run WinMain first (I do have a reason for using both). I'm running windows 7 with mingw if that helps anything.

    Read the article

  • static, define, and const in C

    - by yCalleecharan
    Hi, I've read that static variables are used inside function when one doesn't want the variable value to change/initialize each time the function is called. But what about defining a variable static in the main program before "main" e.g. #include <stdio.h> static double m = 30000; int main(void) { value = m * 2 + 3; } Here the variable m has a constant value that won't get modified later in the main program. In the same line of thought what difference does it make to have these instead of using the static definition: const double m = 30000; or #define m 30000 //m or M and then making sure here to use double operations in the main code so as to convert m to the right data type. Thanks a lot...

    Read the article

  • checking whether 4 points in a plane define a square ??

    - by osabri
    how to check whether 4 points in the plane define a square? what's the function which given a point and a value of the area of a square as input parameters returns four squares(define a corresponding type) with sides parallel to the x axis and y axis this how i start: #include <stdio.h> #include<math.h> struct point{ float x; float y; } typedef struct point POINT; struct square{ struct point p1; struct point p2; struct point p3; struct point p4; } typedef struct square SQUARE; int main() { int point; printf("point coordinate"); printf("\n\n"); printf("enter data\n");

    Read the article

  • Why would I get a bus error or segmentation fault when calling free() normally?

    - by chucknelson
    I have a very simple test program, running on Solaris 5.8: #include <stdio.h> #include <stdlib.h> int main(void) { char *paths; paths = getenv("PATH"); printf("Paths: %s\n", paths); free(paths); // this causes a bus error return 0; } If I don't call free() at the end, it displays the message fine and exits. If I include the free() call, it crashes with a bus error. I've had other calls to free(), in other programs, cause segmentation faults as well. Even if I allocate the memory for *paths myself, free() will cause a bus error. Is there some reason trying to free up the memory is causing a crash?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >