Accueil > > > CONCATÉNATION DE DEUX FIHCIER
CONCATÉNATION DE DEUX FIHCIER
Information sur la source
Description
Ce programme concatène deux fichiers, il est écrit en c.
Source
- /*********************************************************************************/
- /*Ce programme est sous license GNU */
- /*El Antri Abdellah (Djillali Liabes university, Informatic departement, Algeria)*/
- /*E-Mail: El_Emir_2002@yahoo.fr */
- /*********************************************************************************/
-
- /*-------------------------------------------------------------------------*/
- /* Compiled with TC++ 3 under windows */
- /* Use cc to compil programme under unix/linux */
- /*-------------------------------------------------------------------------*/
-
- #include<conio.h>
- #include<stdio.h>
- #include<stdlib.h>
-
- int main(int argc,char **argv)
- {
- char buf[2*1024], fname_src[50], fname_dest[50];
- FILE *src,*dest;
- int copyed, read, nbr_err;
-
- printf("\n\r Copyright(C), El Antri Abdellah 2001\n");
- printf("\n\r *****************************************************************************");
- printf("\n\r *This program concatenate the file src in the end of file dest. *");
- printf("\n\r *if the file dest does not exist the programme create it and copy src in it.*");
- printf("\n\r *file src and file dest must be in current directory *");
- printf("\n\r *****************************************************************************");
- if(argc != 3)
- {
- printf("\n Name of file src:");scanf("%s",fname_src);
- printf("\n Name of file dest:");scanf("%s",fname_dest);
- }
- else if (argc == 3)
- {
- strcpy(fname_src, argv[1]);
- strcpy(fname_dest, argv[2]);
- }
- else {
- printf("\n\r Syntax error: Concat name_file_src name_file_dest or concat.");
- printf("\n\r Hit key ..");
- exit(1);
- }
-
- if((dest = fopen(fname_dest,"a+")) == NULL)
- {
- printf("\n Erreur: can't open or create %s",fname_dest);
- exit(1);
- }
- if((src = fopen(fname_src,"r")) == NULL)
- {
- printf("\n Erreur: can't open %s",fname_src);
- fclose(dest);
- exit(1);
- }
- printf("\nGo!\n");
- while(!feof(src))
- {
- printf(".");
- nbr_err = 0;
- read = 0;
- do
- {
- nbr_err = nbr_err + 1;
- read = fread(buf,sizeof(buf),1,src);
- }while (read != 1 && nbr_err < 5);
- if(nbr_err == 5)
- {
- printf("\n\r Error: Read from %s",fname_src);
- printf("\n\r Hit key ..");
- getch();
- exit(1);
- }
- nbr_err = 0;
- copyed = 0;
- do
- {
- nbr_err = nbr_err + 1;
- copyed = fwrite(buf,sizeof(buf),1,dest);
- }while( copyed != 1 && nbr_err < 5);
- if(nbr_err == 5)
- {
- printf("\n\r Error: Write to %s",fname_dest);
- printf("\n\r Hit key ..");
- getch();
- exit(1);
- }
-
- }
- fclose(src);
- fclose(dest);
- return(0);
-
- }
/*********************************************************************************/
/*Ce programme est sous license GNU */
/*El Antri Abdellah (Djillali Liabes university, Informatic departement, Algeria)*/
/*E-Mail: El_Emir_2002@yahoo.fr */
/*********************************************************************************/
/*-------------------------------------------------------------------------*/
/* Compiled with TC++ 3 under windows */
/* Use cc to compil programme under unix/linux */
/*-------------------------------------------------------------------------*/
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char **argv)
{
char buf[2*1024], fname_src[50], fname_dest[50];
FILE *src,*dest;
int copyed, read, nbr_err;
printf("\n\r Copyright(C), El Antri Abdellah 2001\n");
printf("\n\r *****************************************************************************");
printf("\n\r *This program concatenate the file src in the end of file dest. *");
printf("\n\r *if the file dest does not exist the programme create it and copy src in it.*");
printf("\n\r *file src and file dest must be in current directory *");
printf("\n\r *****************************************************************************");
if(argc != 3)
{
printf("\n Name of file src:");scanf("%s",fname_src);
printf("\n Name of file dest:");scanf("%s",fname_dest);
}
else if (argc == 3)
{
strcpy(fname_src, argv[1]);
strcpy(fname_dest, argv[2]);
}
else {
printf("\n\r Syntax error: Concat name_file_src name_file_dest or concat.");
printf("\n\r Hit key ..");
exit(1);
}
if((dest = fopen(fname_dest,"a+")) == NULL)
{
printf("\n Erreur: can't open or create %s",fname_dest);
exit(1);
}
if((src = fopen(fname_src,"r")) == NULL)
{
printf("\n Erreur: can't open %s",fname_src);
fclose(dest);
exit(1);
}
printf("\nGo!\n");
while(!feof(src))
{
printf(".");
nbr_err = 0;
read = 0;
do
{
nbr_err = nbr_err + 1;
read = fread(buf,sizeof(buf),1,src);
}while (read != 1 && nbr_err < 5);
if(nbr_err == 5)
{
printf("\n\r Error: Read from %s",fname_src);
printf("\n\r Hit key ..");
getch();
exit(1);
}
nbr_err = 0;
copyed = 0;
do
{
nbr_err = nbr_err + 1;
copyed = fwrite(buf,sizeof(buf),1,dest);
}while( copyed != 1 && nbr_err < 5);
if(nbr_err == 5)
{
printf("\n\r Error: Write to %s",fname_dest);
printf("\n\r Hit key ..");
getch();
exit(1);
}
}
fclose(src);
fclose(dest);
return(0);
}
Conclusion
Tout vos questions; propositions seront les bien venu.
Email: El_Emir_2002@yahoo.fr
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
MATRICE TEMPLATEMATRICE TEMPLATE par hjr2610
Cliquez pour lire la suite par hjr2610 RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|