C on Cygwin using Gcc stat function {Resolved}
hello, excuse this work since im not that familiar with C but my university assignment says i must use it for this application.
I have to make a application to copy files with confirm overwrites i seem to have hit an issue
Im compiling this code using the Cygwin VM running on Windows XP compiling with GCC. can anyone see what is wrong with this code ?
Code:
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
struct stat src_info;
struct stat dest_info;
int main(int argc, char **argv[])
{
//make sure we have a valid number of arguments
if (argc == 3)
{
printf("Source: %s\nDestination: %s\n", argv[1], argv[2]);
if (_stat(argv[1], &src_info) == -1) { printf("Error with source could not get i-node\n"); exit(0); }
if (_stat(*argv[2], &dest_info) == -1) { printf("Error with destination could not get i-node\n"); exit(0); }
}
}
i compile in Cygwin using...
$ gcc -o bin/safecp safecp.c
safecp.c: In function `main':
safecp.c:15: warning: passing arg 1 of `_stat' from incompatible pointer type
thank you for your help sam
Re: C on Cygwin using Gcc stat function
Looks like you have a stray '*' before the filename the second time you call _stat. This will result in passing a character instead of a char*, which just could cause that warning.
Good luck!
Edit: in addition, your declaration for main is wrong, which is what is causing the problem in the first place:
try changing "char** argv[]" to "char* argv[]".
Re: C on Cygwin using Gcc stat function
thank u, but my lecturer explained about the **argv today since its an array of strings. and he said the 2 stars are needed. will give it a shot
WoW it worked thanks !
ive decided i hate C C# all the way :)
Re: C on Cygwin using Gcc stat function {Resolved}
There are two legal ways of declaring argv: char **argv and char *argv[]. Maybe argv[][] is legal too, but I don't think so.
It's a bit early to hate C, don't you think?
Re: C on Cygwin using Gcc stat function {Resolved}
yeah i guess had to do c last year at uni as well, but im so used to C#, java & php everything just takes 200 times longer.
I think all you people that work with C through choice deserve a heck of respect if i had a hat it would come off to a C / C++ developer, me I like cheap, dirty and fast :)