![]() |
| | #1 |
| Registered User Join Date: Aug 2009
Posts: 15
| i have Problem to understand FILE in C language , i think more example can be solve my probleam , i make this segment to make better understand for i and all of your guys That problem have (in better way i want to all of you to share your C FILE example heir to help me and each oder ) Code: //=================================================================================
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *in,*out;
char ch;
in = fopen("/home/arash/A.txt" ,"w");
if (!in) {
printf("\n Can't openning a file .\n");
getchar();
exit(1);
}
printf("\n ENTER >> # << for END . \n");
do {
ch = getchar();
putc(ch,in);
}while (ch != '#');
fclose(in);
out = fopen("/home/arash/Documents/B.txt","w");
if (!out) {
printf("\n Can't openning a file .\n");
getchar();
exit(1);
}
in = fopen("/home/arash/A.txt" ,"r");
if (!in) {
printf("\n Can't openning a file .\n");
getchar();
exit(1);
}
do {
ch =getc(in);
putc(ch,out);
}while (ch != EOF);
fcloseall();
printf("\n file transfered ");
printf("\n\t\t >> Good luck << \t\t\n");
getchar();
return 0;
}
//---------------------------------------
//
// ENTER >> # << for END .
//When day When time WhiteCrow1 comeing back.
//(WhiteCrows1)
//#
//
// file transfered
// >> Good luck <<
//
//---------------------------------------
//=================================================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
FILE *fp;
char str[80];
if (!(fp = fopen("test.txt" , "w+"))) {
printf("\n Cant't opening the file . \n");
getchar();
exit(1);
}
printf("\n >> Enter strings ( press ENTER button for end ) <<\n");
while (1) {
gets(str);
if (!(str[0]))
break;
strcat(str,"\n");
fputs(str,fp);
}
rewind(fp);
printf("\n The content of file is : \n\n");
fgets(str,79,fp);
while (!feof(fp)) {
printf("%s" ,str);
fgets(str,79,fp);
}
fclose(fp);
getchar();
return 0;
}
//---------------------------------------
//
// >> Enter strings ( press ENTER button for end ) <<
//This is an example for EDU.
//
//
// The content of file is :
//
//This is an example for EDU.
//
//---------------------------------------
//=================================================================================
>> Sorry my EN i cant speak EN very will but i can understand << |
| arastoo.s is offline | |
| | #2 |
| Registered User Join Date: Sep 2006
Posts: 3,720
| This is all I have about FILE in C: Code:
FILE (type)
File control structure for streams.
typedef struct {
short level;
unsigned flags;
char fd;
unsigned char hold;
short bsize;
unsigned char *buffer, *curp;
unsigned istemp;
short token;
} FILE;
Defined in stdio.h
|
| Adak is offline | |
| | #3 |
| Registered User Join Date: Aug 2009
Posts: 15
| tnx a lot |
| arastoo.s is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 16,078
| So why do you need to peek inside the FILE structure?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2010 Ultimate, C++0x "Thanks Elysia. You're a programming master! How the hell do you know every thing?" "Thanks for all your help. It's obvious yall really know what you're talking about when it comes to OOP/C++ stuff." Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #5 |
| Registered User Join Date: Aug 2009
Posts: 15
| |
| arastoo.s is offline | |
| | #6 |
| and the hat of Destiny Join Date: Aug 2001 Location: The edge of the known universe
Posts: 22,495
| But every different compiler can have a different FILE structure. It can even change between versions of the same compiler. You can't really look at just one thing and figure out something, you really need to grab the whole code for the C standard library to make any sense of it all. |
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|