Thread: Error while trying to initialize pointer to a struct!

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    Arrow Error while trying to initialize pointer to a struct!

    I wrote a program about structs and pointers...but i think i have one mistake! Please take a look at the code:

    I suppose my serious problem is only at the red mark and more specific when initializing the pointer! I hope so...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    struct Packet{
    	int id;
    	char content[5];
    };
    
    int intit_Max(struct Packet A[], int size){
    	int i, j, maxS;
    	struct Packet max5;
    		for(i=0; i<size; i++){
    			A[i].id=rand();
    			for(j=0; j<4; j++){
    				A[i].content[j]=(char)(rand()%26+'a');
    				A[i].content[5]='\0';
    				printf("%12d%s\n", A[i].id, A[i].content);
    			}
    			
    			maxS=A[0].id;
    				for(i=0; i<size; i++){
    					if( A[i].id > maxS ){
    						maxS=A[i].id;
    							return maxS;
    					}
    				}
    		}
    }
    
    int main(void){
    	struct Packet A[10];
    	struct Packet *myS;
    		myS = init_Max(A, 10);
    		printf("\nMax: %d%f\n", myS.id, myS.content);
    }
    
    Thank you in advance...

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    init_Max return int. and you assigned to ..?!

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Also tried to use "." on a pointer...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help assignment due tomorrow
    By wildiv in forum C Programming
    Replies: 6
    Last Post: 01-27-2010, 08:38 PM
  2. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  3. pointer problem or so...
    By TL62 in forum C Programming
    Replies: 19
    Last Post: 01-12-2008, 11:45 PM
  4. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  5. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 10:24 AM