Re: passing a pointer to a struct to a function that uses ncurses



mark.e.nelson@xxxxxxxxx wrote in news:1143805978.415339.184090
@j33g2000cwa.googlegroups.com:

run.c
#include "myform.h"
#include <string.h>
#include <malloc.h>

malloc.h is non-standard, use stdlib.h.


int main()

int main(void) is better.

{
form_data data;

You have already declared data here to be of type form_data. This has
already allocated space for data.

char *name = "Mark Nelson\0";
char *address = "1 Main Road\0";

Why the \0's at the end?


// data = (form_data) calloc(1, sizeof(form_data));

Why is this line here? Is it commented out in the code that crashes?

strcpy(data.name, name);
strcpy(data.address, address);

struct form_data data = { "Mark Nelson", "1 Main Road" };

The rest is platform-dependent stuff which you might want to take a Unix
related group maybe.

Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)
.



Relevant Pages

  • Re: Can somebody help...
    ... a number of unsafe constructs and non-standard extensions. ... That value is too large to portably store in an int. ... This results in undefined behavior because you lied to printf about what ...
    (comp.lang.cpp)
  • Re: progrm to find a substring in a string
    ... Use either int mainor int main(int argc, ... char **argv). ... CBFalconer as a non-standard but more robust variant. ... This function can be replaced by the standard strstr() function. ...
    (comp.lang.c)
  • Re: int urldecode(char *src, char *last, char *dest)
    ... int post{ ... fgets(input, len+1, stdin); ... char *output; ... You've neither allocated space for 'input', ...
    (comp.lang.c)
  • Re: static members
    ... Lem wrote: ... This header is non-standard. ... > static int dI; ... If you use <iostream>, you need to change that into: ...
    (comp.lang.cpp)
  • Re: file i/o issue
    ... > int main ... Non-standard return value. ... Though it's written about scanf(), ... for the good old days of regular old SPAM. ...
    (alt.comp.lang.learn.c-cpp)