Search Results

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

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

  • Avoid incompatible pointer warning when dealing with double-indirection

    - by fnawothnig
    Assuming this program: #include <stdio.h> #include <string.h> static void ring_pool_alloc(void **p, size_t n) { static unsigned char pool[256], i = 0; *p = &pool[i]; i += n; } int main(void) { char *str; ring_pool_alloc(&str, 7); strcpy(str, "foobar"); printf("%s\n", str); return 0; } ... is it possible to somehow avoid the GCC warning test.c:12: warning: passing argument 1 of ‘ring_pool_alloc’ from incompatible pointer type test.c:4: note: expected ‘void **’ but argument is of type ‘char **’ ... without casting to (void**) (or simply disabling the compatibility checks)? Because I would very much like to keep compatibility warnings regarding indirection-level...

    Read the article

  • An easy way to replace fread()'s with reading from a byte array?

    - by Sam Washburn
    I have a piece of code that needs to be run from a restricted environment that doesn't allow stdio (Flash's Alchemy compiler). The code uses standard fopen/fread functions and I need to convert it to read from a char* array. Any ideas on how to best approach this? Does a wrapper exist or some library that would help? Thanks! EDIT: I should also mention that it's reading in structs. Like this: fread(&myStruct, 1, sizeof(myStruct), f);

    Read the article

  • Printf is not printing anything to output? C++ SDL

    - by Qasim
    I am trying to use "printf" in my Visual C++ project however it is not working. Using Lazy Foo's tutorial, I set up SDL in my project, but when I play it, printf doesnt do anything. #include "SDL.h" #include <stdio.h> int main( int argc, char* args[] ) { printf("Testing"); return 0; } The output looks like this: The program '[4664] SDL Testing.exe: Native' has exited with code 0 (0x0). And that's about it. What could be wrong?

    Read the article

  • converting char array into one int

    - by user1762517
    I can't use atoi, need to do it digit by digit.. How do I save it in a int.. given a char* temp put it all in one int.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main () { char* temp = "798654564654564654"; int i = 0; for (i = 0; i < strlen(temp); i++) { printf("%d", temp[i] - 48); } printf("\n"); }

    Read the article

  • Question about variable definitions in functions.

    - by Kaan Tekelioglu
    Hi. #include <stdio.h> main() { int a; for(a=1; a<=4 && printf("%d ",a); a++) { int a; static int b=a; printf("%d ",(a++)-b); } getchar(); getchar(); } In this code, the printout is 1 0 2 1 3 2 4 3. I understand why the int a; part works differently then the int a which was defined outside the for function, and why static int b; is only defined once with the primary value of a ; but why does the (a++) part in printf affect proceeding values of a? Don't we redefine int a; each time the for function runs? Thanks in advance.

    Read the article

  • Can a pointer ever point to itself?

    - by eSKay
    This question was mentioned here. My doubt is: If a pointer variable has the same address as its value, is it really pointing to itself? For example - in the following piece of code, is a a pointer to itself? #include<stdio.h> int main(){ int* a; int b = (int)&a; a = b; printf("address of a = %d\n", &a); printf(" value of a = %d\n", a); } If a is not a pointer to itself, then the same question poses again: Can a pointer point to itself? Also, how is a self pointing pointer useful?

    Read the article

  • usage of 2 charectors in single qoutes in c

    - by user1632141
    #include<stdio.h> int main() { char ch = 'A'; printf("%d\n",'ag'); printf("%d\n",'a'); printf("%d, %d, %d, %d", sizeof(ch), sizeof('a'), sizeof('Ag'), sizeof(3.14f)); return 0; } I used to have many doubts on the output of this question while running on g++ and gcc. But I have cleared almost all the doubts by referring these links: Single and double quotes in C/C++ Single quotes vs. double quotes in C I still need to understand one thing about the output of this question. Can someone please explain the output of printf("%d\n",'ag'); mentioned above in the program. How is it actually stored in the memory? The output for the program on the Linux/GCC platform is: 24935 97 1, 4, 4, 4

    Read the article

  • emacs/Python: running python-shell in line buffered vs. block buffered mode

    - by Begbie00
    Hi all - In a related question and answer here, someone hypothesized that python-shell within emacs(23.2) was block-buffered instead of line-buffered. The recommended fix was to add sys.stdout.flush() to the spot in my script where I want stdio to flush its contents to the python-shell. Is there someway to trick python-shell (running in emacs 23.2 on Windows, not Linux) into either a) thinking it's attached to a TTY or b) using line-buffered instead of block-buffered mode? I don't see why I'd be able to do this in IDLE but not emacs. I'd rather customize emacs than add sys.stdout.flush() throughout my scripts. Call me lazy :-). Thanks, Mike

    Read the article

  • stack of a c program

    - by ckarthickit
    how the stack would look like for the following program if I give input as 5. #include <stdio.h> int fibonacci(int number) { int retval; if (0 == number){ return 0; } if (1 == number){ return 1; } return(fibonacci(number-1) + fibonacci(number-2)); } int main() { int number = 0; int fibvalue = 1; while (1){ printf("please enter the number\n"); scanf("%d", &number); fibvalue = fibonacci(number); printf("computed fibonacci value %d\n", fibvalue); } return 1; } also give me links where i can learn about it

    Read the article

  • strstr whole string match

    - by clay
    I'm trying to match the whole string and not just part of it. For instance, if the needle is 2, I would like to match just the string 2 and not 20, 02, or 22 or anything related. I'm using strstr as: #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { FILE *file; char l[BUFSIZ]; int linenumber = 1; char term[6] = "2"; file = fopen(argv[1], "r"); if(file != NULL) { while(fgets(l, sizeof(l), file)){ if(strstr(l, term) != NULL) { printf("Search Term Found at %d!\n", linenumber); } ++linenumber; } } else { perror(argv[1]); } fclose(file); return 0; }

    Read the article

  • How can a FILE* (pointer to a struct) be tested (if == NULL)?

    - by m4design
    I was playing around with C, anyways I was thinking how can file pointer (which points to a struct type), be tested if NULL as for instant: FILE *cfPtr; if ( ( cfPtr = fopen( "file.dat", "w" ) ) == NULL ) I tried to do that myself, but an error occurs. struct foo{ int x; }; struct foo bar = {0}; if (bar == NULL) puts("Yay\n"); else puts("Nay"); error C2088: '==' : illegal for struct Here's the FILE deceleration in the stdio.h file: struct _iobuf { char *_ptr; int _cnt; char *_base; int _flag; int _file; int _charbuf; int _bufsiz; char *_tmpfname; }; typedef struct _iobuf FILE;

    Read the article

  • cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment

    - by user353573
    i have checked asm/ucontext.h it should be sigcontext, but why pop up the error message cannot convert ‘mcontext_t*’ to ‘sigcontext*’ in assignment #include <stdio.h> #include <signal.h> #include <asm/ucontext.h> static unsigned long target; void handler(int signum, siginfo_t *siginfo, void *uc0){ struct ucontext *uc; struct sigcontext *sc; uc = (struct ucontext *)uc0; sc = &uc->uc_mcontext; sc->eip = target; } struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ };

    Read the article

  • how free of memory happen in this case???

    - by Riyaz
    #include <stdio.h> void func(int arr[],int xNumOfElem) { int j; for(j=0; j<xNumOfElem; j++) { arr[j] = j + arr[j]; printf("%d\t",arr[j]); } printf("\n"); } int main() { int *a,k; a = (int*) malloc(sizeof(int)*10); for(k = 0; k<10; k++) { a[k] = k; printf("%d\t",a[k]); } printf("\n"); func(a,10); //Func call free(a); } Inside the the function "func" who will allocate/deallocate memory for dynamic array "arr". arr is an function argument.

    Read the article

  • assignment makes pointer from integer without a cast

    - by mrblippy
    hi, i am trying to make a linked list and create some methods. but i am getting the error assignment makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include "students.h" node_ptr create(void) { node_ptr students = (node_ptr) malloc(sizeof(struct node)); students->ID = 0; students->name = NULL; students->next = NULL; return students; } void insert_in_order(int n, node_ptr list) { node_ptr before = list; node_ptr new_node = (node_ptr) malloc(sizeof(struct node)); new_node->ID = n;//error is here i think while(before->next && (before->next->ID < n)) { before = before->next; } new_node->next = before->next; before->next = new_node; }

    Read the article

  • Is there any way to pass an anonymous array as an argument in C++?

    - by Jeremy Friesner
    Hi all, I'd like to be able to declare an array as a function argument in C++, as shown in the example code below (which doesn't compile). Is there any way to do this (other than declaring the array separately beforehand)? #include <stdio.h> static void PrintArray(int arrayLen, const int * array) { for (int i=0; i<arrayLen; i++) printf("%i -> %i\n", i, array[i]); } int main(int, char **) { PrintArray(5, {5,6,7,8,9} ); // doesn't compile return 0; }

    Read the article

  • How to create custom filenames in C?

    - by eSKay
    Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i = 0; FILE *fp; for(i = 0; i < 100; i++) { fp = fopen("/*what should go here??*/","w"); //I need to create files with names: file0.txt, file1.txt, file2.txt etc //i.e. file{i}.txt } }

    Read the article

  • C Struct : typedef Doubt !

    - by Mahesh
    In the given code snippet, I expected the error symbol Record not found. But it compiled and ran fine on Visual Studio 2010 Compiler. I ran it as a C program from Visual Studio 2010 Command Prompt in the manner - cl Record.c Record Now the doubt is, doesn't typedef check for symbols ? Does it work more like a forward declaration ? #include "stdio.h" #include "conio.h" typedef struct Record R; struct Record { int a; }; int main() { R obj = {10}; getch(); return 0; }

    Read the article

  • What are the implications of using static const instead of #define?

    - by Simon Elliott
    gcc complains about this: #include <stdio.h> static const int YY = 1024; extern int main(int argc, char*argv[]) { static char x[YY]; } $ gcc -c test1.c test1.c: In function main': test1.c:5: error: storage size of x' isn't constant test1.c:5: error: size of variable `x' is too large Remove the “static” from the definition of x and all is well. I'm not exactly clear what's going on here: surely YY is constant? I had always assumed that the "static const" approach was preferable to "#define". Is there any way of using "static const" in this situation?

    Read the article

  • C : Memory layout of C program execution

    - by pavun_cool
    Hi All , I wanted know how the kernel is providing memory for simple C program . For example : #include<stdio.h> #include<malloc.h> int my_global = 10 ; main() { char *str ; static int val ; str = ( char *) malloc ( 100 ) ; scanf ( "%s" , str ) ; printf( " val:%s\n",str ) ; } See, In this program I have used static , global and malloc for allocating dynamic memory So , how the memory lay out will be ... ? Any one give me url , which will have have details information about this process..

    Read the article

  • problem with threads

    - by Nadeem
    i want to be done for 10 times!!, to scan teh number and print it again!!, how i can do that #include <stdio.h> #include <pthread.h> #include <semaphore.h> sem_t m; int n; void *readnumber(void *arg) { scanf("%d",&n); sem_post(&m); } void *writenumber(void *arg) { //int x =3; //while(x>0) //{ //x = x-1; sem_wait(&m); printf("%d",n); //} } int main(){ pthread_t t1, t2; sem_init(&m, 0, 0); pthread_create(&t2, NULL, writenumber, NULL); pthread_create(&t1, NULL, readnumber, NULL); pthread_join(t2, NULL); pthread_join(t1, NULL); sem_destroy(&m); return 0; }

    Read the article

  • Why would you precede the main() function in C with a data type?

    - by Milktrader
    Many are familiar with the hello world program in C #include <stdio.h> main () { printf ("hello world"); return 0; } Why do some precede the main () function with int as in: int main() Also, I've seen the word 'void' entered inside the () as in: int main(void) It seems like extra typing for nothing, but maybe it's a best practice that pays dividends in other situations? Also, why precede main() with an int if you're returning a character string? If anything, one would expect: char main(void) I'm also foggy about why we return 0 at the end of the function.

    Read the article

  • C String input confusion

    - by ahref
    C really isn't my strong point and after reading 3 chapters of a book on the subject and spending ages trying to get stuff working it just doesn't: #include <stdio.h> char *a,*b; int main( ) { char input[10]; fgets(input,sizeof input, stdin); a = input; fgets(input,sizeof input, stdin); b = input; printf("%s : %s",a,b); } I've isolated the problem from my main project. This code is meant to read in two strings and then print them however it seems to be setting a and b to point to input. Sample output from this code when A and B are entered is(don't worry about the \n's i can remove them): A B B : B How do i store the value of input in another variable eg. a or b so that in the above case A B A : B Is output? Thanks

    Read the article

  • Using pow() for large number

    - by g4ur4v
    I am trying to solve a problem, a part of which requires me to calculate (2^n)%1000000007 , where n<=10^9. But my following code gives me output "0" even for input like n=99. Is there anyway other than having a loop which multilplies the output by 2 every time and finding the modulo every time (this is not I am looking for as this will be very slow for large numbers). #include<stdio.h> #include<math.h> #include<iostream> using namespace std; int main() { unsigned long long gaps,total; while(1) { cin>>gaps; total=(unsigned long long)powf(2,gaps)%1000000007; cout<<total<<endl; } }

    Read the article

  • Hex to bin after logical operations

    - by user355926
    I want: 111 || 100 ---> 111, not 1 100 && 100 ---> 100, not 1 101 && 010 ---> 000, not 0 Broken code #include <stdio.h> main(void){ string hexa = 0xff; strig hexa2 = 0xf1; // CONVERT TO INT??? cast int hexa3 = hexa || hexa2; int hexa4 = hexa && hexa2; puts(hexa3); puts(hexa4); }

    Read the article

  • C string program

    - by mrblippy
    Hi, i have been given a task to do ar school that must read three strings in, store the third string in dynamically allocated memory and print out the last 4 letters of the first word alphabetically. Here is the program i have so far but the strings are all stored in different variables, making them hard to sort. if anyone could give me a hand and help me finish this program i would be very grateful. thanks #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char word1[101]; char word2[101]; char* word3; char buffer[101]; scanf("%s", word1); scanf("%s", word2); scanf("%s", buffer); word3 = (char *) malloc(strlen(buffer)+1); strcpy(word3, buffer); return 0; }

    Read the article

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