LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-06-2006, 03:25 PM   #1
strycnine
Member
 
Registered: Jul 2006
Location: Romania
Distribution: Fedora 12
Posts: 160

Rep: Reputation: 31
error_compilation_cast_directory


#include<sys/types.h>
#include<sys/stat.h>
#include<dirent.h>
#include<stdio.h>
#include<stdlib.h>

main()
{
int i;
mode_t mod;
DIR *director;
mod=0777;
for(i=0; i<5; i++)
{
i=(char)i;
if((mkdir(i, mod)) != 0)
{
fprintf(stderr, "Error creating directory!!\n");
exit(1);
}
if((director=opendir(i)) == NULL)
{
fprintf(stderr, "Error opening directory %d\n", i);
exit(1);
}

}
return 0;
}
I have this program
t compilation it gives me this errors:
dir2.c: In function `main':
dir2.c:16: warning: passing arg 1 of `mkdir' makes pointer from integer without a cast
dir2.c:21: warning: passing arg 1 of `opendir' makes pointer from integer without a cast

how do I use this cast thing??
the program is must do I simple task
creat an folder named 0
and then enter 0 and create 1...and so on until 5

thx

If you have link where I can learn about C functions(for linux or windows) with examples please share
thx again
 
Old 11-06-2006, 03:39 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Put your code in [code] tags to keep indentation, and use a monospace font.

Code:
i=(char)i;
This isn't useful, unless you are trying to truncate the value to 8 bits and even then it is system dependent.
Code:
if((mkdir(i, mod)) != 0)
You are supposed to pass a char*, not an int as the first parameter, just like the compiler told you
Code:
if((director=opendir(i)) == NULL)
Ditto, and be consisten about the use of NULL or 0. I prefer 0 myself.

Isolate the inside of the loop into a function, then just call it how ever many times you need to.
Code:
foo("0");
foo("1");
foo("2");
foo("3");
...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration