C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 15th, 2002, 04:19 AM
empty empty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Australia
Posts: 9 empty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to empty Send a message via AIM to empty
file merger

Im writing a file merger mainly for concating phrack issues =P - but it compiles and doesnt wanna open files and keeps crashing =\ quite odd - if anyone can help would be appriecated - here is the code :
PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void readstdin(char *array, char *strbuff);

int main()
{
   
int ic2;
   
char c 'y';
   
char *base;
   
char *filem;
   
char *strbuff = ( char* ) calloc1024sizeof(char) );
   
FILE *fp1;
   
FILE *fp2;

   
printf("Choose base file ?\n>>");
   
readstdin(basestrbuff);
   
freestrbuff );
   
fp1 fopen(base"a+");
   while( !
fp1 ) {
         
printf("- failed opening file -\n");
         
printf("Choose base file ?\n>>");
         
readstdin(basestrbuff);
         
freestrbuff );
         
fp1 fopen(base"a");
   }

   while( 
!= 'n' ) {
      
printf("Choose file to merge ?\n>>");
      
readstdin(filemstrbuff);
      
freestrbuff );
      
fp2 fopen(filem"rb");
      while( !
fp2 ) {
         
printf("- failed opening file -\n");
         
printf("Choose file to merge ?\n>>");
         
readstdin(filemstrbuff);
         
freestrbuff );
         
fp2 fopen(filem"rb");
      }

      while( (
c2 fgetc(fp2)) != EOF ) {
         
fputc(c2fp1);
      }
      
fclose(fp2);

      
printf("\nWould you like to merge a file ?");
      
scanf("%c");
   }
   
fclose(fp1);

   
system("pause");
  return 
0;
}

void readstdin(char *array, char *strbuff)
{
   
scanf"%s"strbuff );
   array = ( 
char* ) callocstrlen(strbuff), sizeof(char) );
   
strcpy( array, strbuff );


NB: used PHP tags but its C

Reply With Quote
  #2  
Old November 15th, 2002, 04:47 AM
matj222 matj222 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: australia
Posts: 16 matj222 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
HI ALEN

Well i would help u if u werent such a newb
how found da best book on python, it called "core python programming"
heard of it??

Reply With Quote
  #3  
Old November 15th, 2002, 12:17 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
one problem i can see at the first glance:
PHP Code:
 void readstdin(char *array, char *strbuff)
...
   array = ( 
char* ) callocstrlen(strbuff), sizeof(char) ); 


you assign to the char*, but this makes "array" a local copy (!) in the scope of "readstdin()".

you need to pass a pointer to the pointer or a reference to the pointer.
eg.
PHP Code:
 void readstdin(char **array, char *strbuff)
{
   
scanf"%s"strbuff );
   *array = ( 
char* ) callocstrlen(strbuff), sizeof(char) );
   
strcpy( array, strbuff );



or you can allocate the memory in the main function instead before calling readstdin()
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #4  
Old November 15th, 2002, 07:41 PM
empty empty is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Australia
Posts: 9 empty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to empty Send a message via AIM to empty
hmm - I tried that but same thing: it gets the base file now and crashes when opening the file to be appended.
Plus one minute Dev-C++4 was throwing an error -

d:\my documents\projects\untitled1.c: In function `main':
d:\my documents\projects\untitled1.c:18: warning: passing arg 1 of `readstdin' from incompatible pointer type
d:\my documents\projects\untitled1.c:25: warning: passing arg 1 of `readstdin' from incompatible pointer type
d:\my documents\projects\untitled1.c:32: warning: passing arg 1 of `readstdin' from incompatible pointer type
d:\my documents\projects\untitled1.c:39: warning: passing arg 1 of `readstdin' from incompatible pointer type
d:\my documents\projects\untitled1.c: In function `readstdin':
d:\my documents\projects\untitled1.c:62: warning: passing arg 1 of `strcpy' from incompatible pointer type

- then iI compile again and it does, very odd.
Also wondering if that is a problem why doesnt Dev-C++ catch it ?

Last edited by empty : November 15th, 2002 at 07:46 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > file merger

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap