question, can you have more than one getchar in a program? cause everytime i have more than one getchar, with an if/else following, the if's and else's get ignored.
here's teh code:
Code:
/*
* copy.c
*
*
* Created by Peter Noone on 4/6/06.
* Copyright 2006 __MyCompanyName__. All rights reserved.
*
*/
#include <stdio.h>
int main()
{
char q;
char a;
char original[50];
char orig[50];
char file[10];
char dest[50];
char cp[100];
printf("where is the file you would like to copy? \nif the file is on the desktop, type \"y\" \nif not, type \"n\" \n");
q=getchar();
if(q=='y')
{
printf("now type the file name.\n");
scanf("%s", &file);
sprintf(original,"~/desktop");
sprintf(orig,"desktop/%s",file);
}
else
{
printf(" type the full path of the file, start with \"/desktop,\" with a \"/\" \n between each foler. \n");
scanf("%s",&orig);
}
if(q=='y')
{
printf("would you like the copy made to the same location? (y/n)\n");
a=getchar();
if(a=='y')
{
sprintf(dest,original);
}
}
else
{
printf("where would you like this file to be copied to?\n");
printf("type the full path of the destination. \n");
scanf("%s",dest);
}
sprintf(cp,"cp ~/%s ~/%s", orig, dest);
system(cp);
printf("DONE!");
return(0);
}
and here's what i get when i run it (it only works if i chose a file that was on the desktop. i.e. if i chose "y" at the first option)
Code:
new-host-2:/users/peter/desktop/other/programming Peter$ ./copy
where is the file you would like to copy?
if the file is on the desktop, type "y"
if not, type "n"
y
now type the file name.
5g.scpt
would you like the copy made to the same location? (y/n)
cp: /Users/Peter/??.?: Invalid argument
DONE!
thanks