WHEN I TRY TO OPEN FILE IN APPEND MODE ,IT CREATES THE FILE BUT IT SAYS "IN-VALID ENCODING " ALONG WITH THE FILE-NAME ........I HAVE PASSED THE ARRAY OF STRINGS CORRECTLY IN string moreover the strings in "string" are sorted .....any string in "string" is made up of only 4 characters "A","G","T","C".

#include <malloc.h>


int check_duplication_write(int *no_of_strings,char *file_name,char **string){
    char *dest;
    int i,result;
    int temp_length=LENGTH-FIRSTCHARACTERS;//no need of writing a null character in the file
    char temp[temp_length];

    dest=(char *)malloc(1024*1024*1024);
    char result_files[FIRSTCHARACTERS+5];


            //the two adjacent strings have first four characters same

                //the two adjacent string are not exactly same


            }else{}//bypass if we find adjacent string exactly same

            //writing to the file should be done here.

            FILE *intermediate_files=fopen(result_files,"a");
            dest=(char *)malloc(1024*1024*1024);
    return result;

A few suggestions:

malloc() is defined in the include file "alloc.h", not "malloc.h". ;)

Without the stdio.h include file, I'm not surprised you're having problems opening files and such. ;)

After you malloc() for an array (especially after such a large one), be sure to check the returned pointer address to be sure the request succeeded, and is not NULL.

btw, the return addy from malloc() doesn't need to be cast, 99.9% of the time.

Edited 5 Years Ago by Adak: n/a

I beg to differ. malloc is defined in some implementation-defined library and declared in <stdlib.h>.

I beg to differ. malloc is defined in some implementation-defined library and declared in <stdlib.h>.

Well, I figured he was going for "alloc.h", since he's just one letter off. Either header file (alloc.h or stdlib.h), will have the needed declarations:

malloc Allocates memory.

void *malloc(size_t size);

Prototype in:
alloc.h stdlib.h

malloc allocates a block of size bytes from the memory heap. It allows a
program to allocate memory explicitly as it's needed, and in the exact
amounts needed.

The heap is used for dynamic allocation of variable-sized blocks of memory.
Many data structures, such as trees and lists, naturally employ heap memory

All the space between the end of the data segment and the top of the program
stack is available for use in the small data models, except for a small
margin immediately before the top of the stack.

This margin is intended to allow the application some room to make the stack
larger, in addition to a small amount needed by DOS.

In the large data models, all the space beyond the program stack to the end
of available memory is available for the heap.

Return Value:
On success, malloc returns a pointer to the newly allocated block of memory.

If not enough space exists for the new block, it returns null. The contents
of the block are left unchanged.

If the argument size == 0, malloc returns null.

malloc is available on UNIX systems and is defined in ANSI C.


#include <stdio.h>
 #include <string.h>
 #include <alloc.h>    //or <stdlib.h>
 #include <process.h>

 int main(void)
    char *str;

    /* allocate memory for string */
    if ((str = malloc(10)) == NULL)
       printf("Not enough memory to allocate buffer\n");
       exit(1);  /* terminate program if out of memory */

    /* copy "Hello" into string */
    strcpy(str, "Hello");

    /* display string */
    printf("String is %s\n", str);

    /* free memory */

    return 0;

Only <stdlib.h> exists in any form of the C standard, or on my system.

% cat file.c 
#include <alloc.h>
#include <stdio.h>

int main(void)
        char *x = malloc(3);
        printf("%s", x);
        return 0;
% cc file.c 
file.c:1:19: error: alloc.h: No such file or directory
file.c: In function ‘main’:
file.c:5: warning: incompatible implicit declaration of built-in function ‘malloc’

Don't encourage people to use nonstandard headers.

Edited 5 Years Ago by Trentacle: forgot &lt;stdio.h&gt;

>Don't encourage people to use nonstandard headers.
Indeed, especially when the nonstandard header is also completely unnecessary.

This article has been dead for over six months. Start a new discussion instead.