C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-10-2010, 04:29 AM   #1
Registered User
 
arastoo.s's Avatar
 
Join Date: Aug 2009
Posts: 15
Question Need more example

HI
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   Reply With Quote
Old 02-10-2010, 05:56 AM   #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   Reply With Quote
Old 02-10-2010, 05:58 AM   #3
Registered User
 
arastoo.s's Avatar
 
Join Date: Aug 2009
Posts: 15
tnx a lot
arastoo.s is offline   Reply With Quote
Old 02-10-2010, 06:29 AM   #4
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 02-10-2010, 06:36 AM   #5
Registered User
 
arastoo.s's Avatar
 
Join Date: Aug 2009
Posts: 15
Quote:
Originally Posted by Elysia View Post
So why do you need to peek inside the FILE structure?
Because i want get better understand about file
arastoo.s is offline   Reply With Quote
Old 02-10-2010, 09:59 AM   #6
and the hat of Destiny
 
Salem's Avatar
 
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.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 12:12 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22