labprog10-2010

labprog10-2010 -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Swinburne University of Technology Faculty of Engineering and Industrial Sciences HES1300 Robotics & Mechatronics Project 1 Laboratory assignment 10: Your task for this session is as follows: 1. Carefully study the following program and make sure you fully understand how it works (it meant to read a file and print its content to the screen). Pay particular attention to the way that a file has been accessed (open and read). 2. Modify this program so it would copy the content of a file into another file. 3. Further modify the program to also print the file content into computer screen in alphabetic order (use bubble sort similar to previous week). 4. Write comments for all the functions (including main) in your program.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <stdio.h> #include <string.h> #include <stdlib.h> int readWord(FILE *in, char aWord); FILE * openFile(); int main() { char aWord[100]; FILE *in; in=openFile(); while(readWord(in,aWord)!=EOF) { printf("%s ",aWord); } printf("\n"); fclose(in); return(0); } FILE * openFile() { FILE *in; char filename[1000]; printf("Please enter the input file name including its path\n"); scanf("%s",filename); if ((in = fopen (filename,"r")) == NULL){ fprintf(stderr, "Can't open the input file.\n"); printf("Program is terminated . ..\n"); exit(1); } return in; } int readWord(FILE *in, char aWord) { return fscanf(in,"%s",aWord); }...
View Full Document

Ask a homework question - tutors are online