http://pc-dojo.ro

Index | Banner Xchange | Forum | Chat | E-zine | Competitie | E-mail | Tzoale | Bani | Despre

Competitie:

Login:

Parola:

User: Neautentificat.
User nou?

 

 free @pc-dojo.ro

Email Login

Parola

Utilizatori noi
sign up!

detalii...

 Va multumim pentru eventualul vot pe care ni-l puteti acorda cu un singur click :
Vot in Romanian TOP 100
Aduti si tu contributia la dezvoltarea pc-dojo. Un vot inseamna un sustinator, o persoana care este de acord cu noi, un motiv suplimentar de mentinere pc-dojo pe net-ul romanesc.


Tzoale de hackeri:







Website Owners:
Start making real money on a pay per click basis.
10 cents!

 


Bride.Ru

C i/o tutorial

de bugghy

/----------------\
| C i/o tutorial |
\----------------/
v1.0a

Written by: Bugghy
E-mail: bugghy@home.ro
URL: www.bugghy.home.ro

Comments/errors/bugs/jokes > bugghy@home.ro

CONTENTS
=====================================

1. Introduction
2. Basic understanding
3. Synopsis
4. Basic help
5. Link of the day
6. Last words

=====================================

1. Introduction
===============

You all wanna make nifty programs in C that open files, write to them,
do nasty things with them ... but you don't wanna use the system() function.
So here's how:

2. Basic understanding
======================

For accessing files in C you must use a FILE pointer to define that file
aka let the program now that you are accessing a file.
FILE *fp;
To start writting to a file you first have to open it:
fopen("/var/log/dmesg","w");
- fopen = function used to open a file:
- "/var/log/dmesg" = filename to open
- "w" = openned for writting

You can open a file in the following modes:

r - open for reading
w - open for writing (file need not exist)
a - open for appending (file need not exist)
r+ - open for reading and writing, start at beginning
w+ - open for reading and writing (overwrite file)
a+ - open for reading and writing (append if file exists)

Example:
FILE *fp;
if ((fp = fopen("/var/log/mesg", "r")) == NULL )
{
printf("Couldn't open file");
exit(-1);
}
// tries to open a file for reading

After you've done your job (aka you wrote to the file ...) it's time to close
it:
fclose(fp);
Now we can think of writting/reading to/from file: fprintf, fscanf
fprintf(fp,"it werks\n");
If we open a binary file then we use: fwrite, fread

Example:
FILE *fp;
if ((fp = fopen("/var/log/dmesg", "wb");
char ch[10]="funnywabit";
fwrite(ch, sizeof(ch[0]), sizeof(ch)/sizeof(ch[0]), fp);

3. SYNOPSIS
===========
#include

FILE *fopen (const char *path, const char *mode);
int fclose( FILE *stream);
int fprintf(FILE *stream, const char *format, ...);
int fscanf( FILE *stream, const char *format, ...);
size_t fwrite( const void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream);

4. BASIC HELP
============

This is just a tut to real BASIC i/o programming.
Read all man pages for more info (man fprintf ...)
It's real simple after some practice.

5. Link of the day
==================

Great tuts: blacksun.box.sk neworder.box.sk black.box.sk ...

6. Last words
=============

If you wanna clarify some misunderstandings in the text, add something,
bugs/comments/... mail bugghy@home.ro

THE USUAL DISCLAIMER:
---------------------
This file is for [of course] informational purposes only. I
don't take responsibility for anything anyone does after reading this file.

Gr33tz:
vMatriCS.nET , anyone that helped me (they know who they are)




Toate drepturile rezervate © www.pc-dojo.ro
Reproducerea permisa doar insotita de acordul autorului sau al site-ului


Arhiva | Adauga un articol | Despre e-zine









Stiri:
  • Forumul pc-dojo si-a mutat locatia, aspectul si rubricile. Daca linkul din site catre forum va duce tot catre vechiul forum dati cateva refreshuri pe http://forum.pc-dojo.ro si ar trebui sa mearga... de obicei dureaza cam 24 de ore pana se propaga update-urile de dns.
    Adaugata de body00, c0der.

  • Forumul pc-dojo si-a mutat locatia, aspectul si rubricile. Daca linkul din site catre forum va duce tot catre vechiul forum dati cateva refreshuri pe http://forum.pc-dojo.ro si ar trebui sa mearga... de obicei dureaza cam 24 de ore pana se propaga update-urile de dns.
    Adaugata de body00, c0der.

  • Forumul pc-dojo si-a mutat locatia, aspectul si rubricile. Daca linkul din site catre forum va duce tot catre vechiul forum dati cateva refreshuri pe http://forum.pc-dojo.ro si ar trebui sa mearga... de obicei dureaza cam 24 de ore pana se propaga update-urile de dns.
    Adaugata de body00, c0der.

  • (propune stire)






    Ustensile gratuite pentru web-site-ul dvs:


    Motor de cautare complex:

    TotalTOP.ro - Topul celor mai bune site-uri romanesti - Votati acest site!!!


    ©2002 - 2004 pc-dojo.ro contact: admin@pc-dojo.ro