Trouble making programs

andy@7:~/Downloads$ gcc munch.c -o munch
gcc: error: munch.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
int max = -1;
int mb = 0;
char* buffer;

if(argc > 1)
    max = atoi(argv[1]);

while((buffer=malloc(1024*1024)) != NULL && mb != max) {
    memset(buffer, 0, 1024*1024);
    mb++;
    printf("Allocated %d MB\n", mb);
}

return 0;

}

The error is saying that your file is not called “munch.c” or you are running gcc from a different folder.
Note 1: to format the code as such in the forum, add at least 4 spaces at the beginning of each code line.
Note 2: change the test “mb != max” with “mb < max” (your max default value is -1)

2 Likes

Thanks, i renamed it from munch.o to munch.c

Now it compiled.

Thanks