Typedef Problem

This is a discussion on Typedef Problem within the C Programming forums, part of the General Programming Boards category; I have created my own structure using typedef but when I go to store values in a created one, I ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    Typedef Problem

    I have created my own structure using typedef but when I go to store values in a created one, I am going incompatible type errors

    Code:
    typedef struct{
    	FILE *fp;
    	char name[50];
    	char line[100];
    	int timestart, timetotal;
    } process;
    
    void newprocess(char n[]){
    	process *new = malloc(sizeof(process));
    	new->name = n;
    When I try to compile this I get error: incompatible types in assignment.

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    You will have to use strncpy() for what you're trying to do, because you can only assign a value to an entire array at declaration. Past that, you have to set values of individual array elements.
    Code:
    char full_name[50] = "Jane Doe";    // Fine.
    
    . . .
    
    char full_name[50];
    full_name = "Jane Doe";    // Invalid.
    Last edited by msh; 10-21-2010 at 02:39 AM.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    1
    you know what this function is not used like this "process *new = malloc(sizeof(process))"

    this is it , "void* malloc()"
    so you should define a structure point to changes its type!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,125
    Quote Originally Posted by 2008hiroki
    you know what this function is not used like this "process *new = malloc(sizeof(process))"

    this is it , "void* malloc()"
    so you should define a structure point to changes its type!
    You are right to say that there is a problem with that line as well, but other than that I do not understand what you are trying to say about "this is it" and "a structure point to changes its type". That line should have been:
    Code:
    process *new = malloc(sizeof(*process));
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. Help...typedef struct...confusing...
    By darkchild in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 08:03 AM
  3. typedef problem
    By dr$brown in forum C Programming
    Replies: 6
    Last Post: 12-25-2004, 12:27 PM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21