I’m currently learning the C language in college so this is a homework assignment but I have a small problem. I’m guessing I’ve just misjudged the syntax or are missing something really obvious. My compiler is telling me that there is:
expected declaration specifiers or “…” before constant
and pointing to the O_RDWR.
I’ve googled and searched on Stack Exchange but there doesn’t seem anything specific to it. Following the syntax in a C reference it’s fine. I’ve looked around and it says I have not predefined the typedef but I’ve tried that to no avail.
I’ve starred the section that is causing the problem according to the compiler with **
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int count;
printf ("This program was called \"%s\".\n",argv[0]);
if (argc > 1)
{
for (count = 1; count < argc; count++)
{
printf("argv[%d] = %s\n", count, argv[count]);
}
}
else
{
printf("The command had no arguments.\n");
}
if (argc == 4)
{
printf("There are the correct number of arguments(4)");
}
else
{
printf("Not enough arguments! please try again");
}
**int open(const char *argv[1], O_RDWR);
return 0;**
}
What are you trying to do by this statement? Compiler treats this as function declaration, not function call. And it fails because O_RDWR is not a type name. If you need to call
open(), syntax shall be like this: