fledgeling's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
69 (0.1 per day)
Joined:
10-October 12
Profile Views:
809
Last Active:
User is offline Jun 21 2014 03:50 AM
Currently:
Offline

Previous Fields

Country:
GR
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Icon   fledgeling has not set their status

Posts I've Made

  1. In Topic: Dynamic memory allocation or just logical failure?

    Posted 21 Apr 2013

    yes i runned it with the debugger and it popped a sigtrap trace/breakpoint trap error when it was running the line where i free the memmory

    View Postjjl, on 21 April 2013 - 11:30 AM, said:

    If you are allocating a dynamic array of pointers, then you cannot allocate it using the size of a char.

    Quote

    array=malloc(mw*sizeof(char)+1);


    The sizeof(char) does not equal sizeof(char*), on 32 bit systems the sizeof(char*) is 4 bytes.

    By making this change the program seems to work properly sometimes but some others it crashes again ...can you explain it to me a bit more or adress me a tutorial or other post that does so ?
  2. In Topic: Dynamic memory allocation or just logical failure?

    Posted 21 Apr 2013

    void dio(FILE *fp3,FILE *fp,int mw , int mc){
    	int i,j=0,answer,found=1,er=0;
    	char **array,hjalp[1000],word[100];
    fp3= fopen("dictionary.txt","r+");
    	if(fp3== NULL)
    	exit (1);
    array=malloc(mw*sizeof(char)+1);
    while (!feof(fp3)){
        
        fscanf(fp3,"%s",hjalp);
        array[j]=malloc(strlen(hjalp)*sizeof(char)+1);
        if (array[j]==NULL) exit(1);
    	strcpy(array[j],hjalp);
        
    	
    
    	j++;
    	}
    
    
    scanf("%s",word);
    	for (i=0;i<j;i++){
    		if (strcmp(array[i],word)==0){
    		free( array[i]);
    		array[i]=malloc(strlen(hjalp)*sizeof(char)+1);
    		if (array[i]==NULL) exit(1);
    		strcpy(array[i],hjalp);
    }
    }
    
    
    
    
    
    
    



    is this any better ? the error comes when i free
  3. In Topic: Dynamic memory allocation or just logical failure?

    Posted 21 Apr 2013

    Well i actually read it but i cant see why that free causes problems. isnt it supposed to free the memory of the specific j raw ? and then malloc again according to the new word i want to save so what goes wrong ?:(
  4. In Topic: Dynamic memory allocation or just logical failure?

    Posted 21 Apr 2013

    ok, i will thanks for you time
  5. In Topic: Dynamic memory allocation or just logical failure?

    Posted 21 Apr 2013

    i will keep that in mind...thanks :D

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

fledgeling hasn't added any friends yet.

Comments

fledgeling has no profile comments yet. Why not say hello?