Topic: Transfer Var to Function


Author: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Date: Sat, 18 Sep 1993 17:17:20 GMT
Raw View
harry#d#.tempelman@canrem.com (Harry. Tempelman) writes:

>Question: How can I pass a variable from one function to another
>function? More specifically, how can I pass filename.BAK from
>function search to function destroy for deletion?

1. Wrong newsgroup.  Try comp.lang.c++ instead.

2. main() should return an int, not void.

3. C++ requires you to use function prototypes, not old-style
   function definitions.  I suggest that you read a C++ book
   if you want to learn C++.

--
Fergus Henderson                     fjh@munta.cs.mu.OZ.AU




Author: harry#d#.tempelman@canrem.com (Harry. Tempelman)
Date: Thu, 16 Sep 93 09:12:00 -0400
Raw View
Question: How can I pass a variable from one function to another
function? More specifically, how can I pass filename.BAK from
function search to function destroy for deletion?

/* Trash program for deleting all .BAK files */

#include<stdio.h>
#include<dir.h>

void main(void);
void span();
void search();
/* char destroy(char); */

void main(void)
{
 search("");
 span("");
}

void span(p)
char *p;
{
 struct ffblk f;
 char n[129];
 int r;

 search(p);
 sprintf(n,"%s\\%s",p,"*.*");
 for(r=findfirst(n,&f,0x0010);!r;r=findnext(&f))
 {
   if(*f.ff_name == '.') continue;
   if(f.ff_attrib & 0x0010)
   {
       sprintf(n,"%s\\%s",p,f.ff_name);
       span(n);
   }
 }
}

void search(p)
char *p;
{
 struct ffblk f;
 char b[81], c[81];
 int r, retval;

 strcpy(b,p);
 strcat(b,"\\*.BAK");
 printf("\nChecking %s",p);
 destroy(b);


}

destroy(x)
char *x;
{
        char b[81];
 struct ffblk f;
 int r;

        strcpy(b,x);
 for(r=findfirst(x,&f,0x0000);!r;r=findnext(&f))
 {
   printf("\nWant to kill %s [Y or N]",f.ff_name);
   if(toupper(getch())=='Y')
   {
       sprintf(b,"%s\\%s",x,f.ff_name);
       remove(b);
       printf(" ZAP");
   }
 }
        return(0);
}

 APEX METALS INC.   .   .   .   .    __|__    .   . harry.tempelman@canrem.com
.   .   .   .   .   .   .   . --o--o--(_)--o--o-- .   .   .   .   .   .   .   .
---
     DeLuxe    1.25 #11534     REALITY.SYS Corrupted: Reboot universe? [Y/N]