Re: how to design an testing example



"Subbu" <mailursubbu@xxxxxxxxx> writes:
qazwsx746@xxxxxxxx wrote:
The content of my program are the following:

#include <stdio.h>
int main(int argc,char *argv[])
{ FILE *fp;
void filecopy(FILE *,FILE *);
if (argc==1)
filecopy(stdin,stdout);
else
while (--argc>0)
if ((fp=fopen(*++argv,"r"))==NULL) {
printf("cat:can't open %s\n",*argv);
return 1;
} else {
filecopy(fp,stdout);
fclose(fp);
}
return 0;
}
void filecopy(FILE *ifp,FILE *ofp)
{int c;
while ((c=getc(ifp))!=EOF)
putc(c,ofp);
}
when I input command lines,for example:cat f:\test\1.cpp (windows xp
is installed in my computer)
the output are :cat f:\test\1.cpp
The angrument which is f:\test\1.cpp donot have work,and output is cat
f:\test\1.cpp
I know the program have no problem.
But I can't run the program corretly?
What should I do?

While passing the file name use "\\" insted of "\".

Please don't top-post. See the following:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

That's not likely to be the problem. A backslash character is
represented as "\\" in a string literal or character constant in C
source code; the syntax doesn't necessarily apply to whatever provides
a program's command-line arguments. <OT>In particular, it's not
likely to apply on Windows.</OT>

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: how to design an testing example
    ... int main ... void filecopy ... when I input command lines,for example:cat f:\test\1.cpp (windows xp ... The angrument which is f:\test\1.cpp donot have work,and output is cat ...
    (comp.lang.c)
  • Re: preprocessor/linker c++ error
    ... $ cat file1.cc ... void f1(int x,int y, int z) ... Novell's Directory Services is a competitive product to Microsoft's ...
    (Debian-User)
  • Re: how to design an testing example
    ... int main ... void filecopy ... expected: cat f:\test\1.cpp ... Nick Keighley ...
    (comp.lang.c)
  • Re: Classes
    ... "Missing identifier before 'Cat' " should make you look carefully at what's ... > int getAge(); ... > void setAge; ... > int itsAge; ...
    (microsoft.public.vc.language)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)