Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

posix - C: read in more than one file -


hey guys using posix api system calls read, write, open, etc. can open, read, write file , copy contents output file. how go copying more 1 file output file using related system calls only?

i have:

filein = open(argv[1],o_rdonly,0); 

to open 1 file.(which argv1 i'd know how argv2 , argv3 etc.)

i tried :

j=0; filein = open(argv[j],o_rdonly,0); 

but prints out contents of argv0 outputfile.

i stuck on next stage more 1 file. (i have eof loop after 1 file exits-how make continue next file).

please me how approach next stage? thanks.

background

argv[0] name of program.

argv[1] 1st command line parameter.

argv[2] 2nd command line parameter.

etc.

so:

  1. start loop @ 1, instead of 0 (i.e., j=0 incorrect).
  2. be sure close file after reading , before opening next file.

algorithm

think algorithm before writing code.

  1. set counter index of first argument.
  2. open file.
  3. assign handle open file.
  4. read file contents.
  5. write (if required) file contents.
  6. close file using handle.
  7. increment counter.
  8. loop until there no more command line arguments.

now can write code.

you might bonus points if include error handling. (what happens when file missing, not readable, file system corrupt, or machine has run out of memory or disk space?)

concatenating files

if want concatenate 2 file names third, need rethink algorithm, , need. there difference between "read first 2 files given on command line , write them third file" , "append files given on command line last file given."

read two, write one

the algorithm:

  1. make sure there 3 parameters.
  2. create file handle variable third file (output).
  3. create file handle variable first file (input).
  4. create file handle variable second file (input).
  5. open first file reading.
  6. open second file reading.
  7. open third file writing.
  8. read contents of first file , write them third file.
  9. read contents of second file , write them third file.
  10. close third file.
  11. close second file.
  12. close first file.

you notice lot of redundancy @ point.

read n, write one

this algorithm bit more challenging, removes redundancy.

  1. make sure there @ least 2 parameters.
  2. open last file writing.
  3. loop on every file name to, not including, last file name given:
    1. open input file reading.
    2. write contents of file last file.
    3. close input file.
  4. close output file.

for need understand argc , relationship argv. in pseudo-code:

if number_of_arguments < 2   print "this program concatenates files; 2 or more file names required."   exit end  int outfile = open arguments[ number_of_arguments ] writing int j = 1  while j < number_of_arguments   int infile = open arguments[ j ] reading   string contents = read infile   write contents outfile   close infile   increment j end  close outfile 

tutorials

if having trouble c syntax, search tutorials. example:


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -