User Profile

Collapse

Profile Sidebar

Collapse
bimbam
bimbam
Last Activity: Mar 8 '08, 01:50 PM
Joined: Aug 17 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • bimbam
    started a topic read float from string and approximation problem
    in C

    read float from string and approximation problem

    Hi,

    I try to read a float in a string using sscanf or atof. It seems to work but then it's a bit strange when I manipulate the value obtained.

    Code:
    float fl;
    char  str[]="1.43"
    
    fl=atof(str);
    
    printf("%f\n",floor(1000.0*fl) );
    These lines return : 1429.000000

    It seems to be due to the precision of the float...
    See more | Go to post

  • bimbam
    replied to using variable names
    in C
    Sorry, that's not what I meant. My question was about the function called "function" in my example that would have as input argument a string and would output the variable of which the name is contained in the string. I realise my explanation is not so clear but it should be easier to understand reading the example at the same time.

    Cheers...
    See more | Go to post

    Leave a comment:


  • bimbam
    started a topic using variable names
    in C

    using variable names

    Hi,

    Does anyone of you knows how to make a string to be interperted as a variable name in C? For example, is there a function so that the following lines print out "test"?

    Code:
    char variable[10];
    strcpy(function("variable"), "test");
    printf("%s\n",variable );
    It would simplify a lot of things to me...

    Cheers
    See more | Go to post

  • bimbam
    started a topic xlib and mouse button
    in C

    xlib and mouse button

    Hi,

    I'm trying to use the Xlib library to detect a mouse button event in C. I'm using linux. I want to run a loop and exit this loop when a mouse button is pressed. It seems possible to me to wait for an event to happen but it it possible to compute something else while we're waiting?

    I thought of something like :

    do {
    ...
    } while !(buttonstate1= =pressed)

    So my question is:...
    See more | Go to post

  • bimbam
    started a topic loading PNG image in C.
    in C

    loading PNG image in C.

    Hi,

    Could anyone tell me how to load a PNG image into memory?

    Regards
    See more | Go to post

  • bimbam
    started a topic qsort of an array of pointers to structures
    in C

    qsort of an array of pointers to structures

    Hi,

    I wish to sort an array of pointers to structures. There must be something I don't get.

    Here is my code:
    [CODE=c]
    ...
    typedef struct
    {
    ...
    time_t time;
    }struct_file;

    main()
    {
    struct_file ** tables;
    ...
    qsort( tables,ntables, sizeof(struct_f ile), cmp_struct);
    }

    int cmp_struct( const void...
    See more | Go to post
    Last edited by bimbam; Sep 29 '07, 10:57 AM. Reason: not finished

  • bimbam
    started a topic passing a (char *) as an argument
    in C

    passing a (char *) as an argument

    Hi,

    I try to write in C a function that can edit a string allocated dynamically. I tried:

    Code:
    int funct(char ** str)
    {
    int n;
    n=strlen("TEST");
    (*str)=malloc(sizeof(char)*(n+1));
    strcpy(*str,"TEST");
    }
    the main is

    Code:
    int main()
    {
    char * str;
    funct(&str);
    printf("%s\n",str);
    }
    ...
    See more | Go to post

  • bimbam
    replied to binary conversion
    in C
    OK.

    So JosAH (or anyone) can you help me?

    Regards.
    See more | Go to post

    Leave a comment:


  • bimbam
    replied to binary conversion
    in C
    Hi,

    I tried to compile the examples you sent me. I try to use a Makefile but I'm not too familiar with it. Could you give me a help? Do I need a header file?

    I called the 2 files you sent me main.c and test.cpp. Here is my makefile:
    Code:
    CC=gcc
    CPP=g++
    CFLAGS=-W -Wall -ansi -pedantic
    CXXFLAGS=-W -Wall -ansi -pedantic
    LDFLAGS=
    EXEC=test
    
    all: $(EXEC)
    ...
    See more | Go to post

    Leave a comment:


  • bimbam
    replied to binary conversion
    in C
    How do you link the 2 files together?

    Regards
    See more | Go to post

    Leave a comment:


  • bimbam
    replied to binary conversion
    in C
    Thanks,

    I'll try that.

    Regards...
    See more | Go to post

    Leave a comment:


  • bimbam
    replied to binary conversion
    in C
    Thank you for the tip.

    I don't use C++ but there might be a function in C to do the same?

    Regards...
    See more | Go to post

    Leave a comment:


  • bimbam
    started a topic binary conversion
    in C

    binary conversion

    Hi,

    I wish to compare 2 black and white images of about 4000 pixels. So I have 2 arrays of 4000 integers int of value 0 or 1. My idea was to convert each array to a single binary number built by putting all the integers one after the other. I could then convert this number to a base 10 number. I would use this number as a signature of each image to compare them.

    The problem is the amount of operations to make to build...
    See more | Go to post

  • Thanks.

    To 'desallocate', is 'free(p)' enough? Or do I have to do everything in reverse to free each field of all the structures, free the structures abd then free the array?
    Regards...
    See more | Go to post

    Leave a comment:


  • Thanks a lot for your answer.

    Everything seems to work. I just want to be sure that I did the memory allocation properly so that nothing will be overwriten later and no memory was wasted.

    Could you quickly have a look at these few lines to see if everything is "perfect"? Do you have suggestions to improve it?

    [code=c]
    #include <stdio.h>
    #include <stdlib.h>
    ...
    See more | Go to post

    Leave a comment:


  • But in that case, how would you allocate dynamically the memory of an array of pointers if not with 'p=calloc(n,siz eof(struct_p*)) '?

    Regards...
    See more | Go to post

    Leave a comment:


  • It works with 'sizeof(struct_ p)' (and '.'). You were right. Thank you for your help.

    Regards...
    See more | Go to post

    Leave a comment:


  • Thank you for your answer.

    I used sizeof(struct_p *) and not sizeof(struct_p ). Does'nt it make any difference? I thought that, this way, the elements of the array would be pointers.

    Regards...
    See more | Go to post

    Leave a comment:


  • dynamic memory allocation of an array of pointers to structures

    Hi,

    I've been trying to allocate dynamicaly an array of pointers to structures. As it didn't work, I tried to reduce the problem as much as possible. This is what I have :

    [code=c]
    #include <stdio.h>
    #include <stdlib.h>

    typedef struct
    {
    int x;
    int y;
    }struct_p;


    int main()
    {
    int i,n=2;
    struct_p *p;...
    See more | Go to post
No activity results to display
Show More
Working...