help with C programming (reading from files and printing them) (not C++)


 
Thread Tools Search this Thread
Top Forums Programming help with C programming (reading from files and printing them) (not C++)
# 1  
Old 02-02-2011
Error help with C programming (reading from files and printing them) (not C++)

I have a file called dvwl.c, and I am running it on a putty (unix server) using:

gcc -Wall -g -o mycode dvwl.c
./mycode 1 /usr/share/dict/words s

What it does is, it opens up words (since i gave that path) and reads the lines skipping the first line (since it says 1, if i put here 3, then it would skip the first 3 lines), then it is supposed to print the lines with all vowels removed (small or big, and not y/Y) and some other character as an argument (i put s for this). So it now print them with all vowels and s removed.

But I get these errors:
dvwl.c: In function âreplaceâ:
dvwl.c:5: warning: implicit declaration of function âtolowerâ
dvwl.c:6: warning: implicit declaration of function âtoupperâ
dvwl.c: In function âmainâ:
dvwl.c:15: error: âtryâ undeclared (first use in this function)
dvwl.c:15: error: (Each undeclared identifier is reported only once
dvwl.c:15: error: for each function it appears in.)
dvwl.c:15: error: expected â;â before â{â token
dvwl.c:31: warning: control reaches end of non-void function

What is wrong with my code? Also what is perror and how do I properly use it, and do i need an exit(1); after i use perror? Also what is wrong with my try/catch?

Code:
#include<stdio.h>

void replace(char *s,char v) {
	while (*s) {
		if ((char)*s!='a' && (char)*s!='e' && (char)*s!='i' && (char)*s!='o' && (char)*s!='u' && (char)*s!=tolower(v)) {
			if ((char)*s!='A' && (char)*s!='E' && (char)*s!='I' && (char)*s!='O' && (char)*s!='U' && (char)*s!=toupper(v)) {
				printf("%c", *s);
			}
		}
		s++;
	}
}

int main(int argc, char **argv) {
	try {
		int g=1;
		char line[30];
		FILE *fr = fopen (argv[2], "r");
		while(fgets(line,30,fr)!=NULL) {
			if (g++>atoi(argv[1])) {
				replace(line,'s');
			}
		}
		fclose(fr);
	}
	catch(Exception e) {
		perror("Usage: %s %s\n",argv[0] ,argv[1]);
		exit(1);
	}
	return 0;
}

# 2  
Old 02-03-2011
This looks a lot like homework. Thread closed until convinced otherwise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help on Reading UNIX Programming Books.

I've purchased few unix/linux programming books and also planning to buy couple of books in future. I've got the following books; Advanced Unix Programming(2nd ed) -- M. Rochkind. Advanced Programming on Unix Environment(3rd ed) -- Late Rick Stevens & Rago. Unix Systems Programming -... (8 Replies)
Discussion started by: vectrum
8 Replies

2. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

3. Shell Programming and Scripting

Printing second column of several files into one

HI All, I have exactly 100 text files with extension .txt. The files contain numbers like this: 1.txt 0.4599994 65914 0.40706193 190743 0.39977244 185019 0.39831382 74906 0.3915928 122428 0.38844505 39999 0.38820446 72691 0.38787442 176430 0.38670844 28791 0.38597047 91091... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

4. Shell Programming and Scripting

Shell programming - running the exe file and printing the output.. ?

hai i have a directory lib in that lib directory i have 10 batch files. step i have to do is 1) EXECUTE ALL THE FILES by using the command dwarfdump <filename>| grep DW_AT_SUN_command_line and put the output in one text file.instead of executing the files for all the 10 files... (13 Replies)
Discussion started by: shenthil76
13 Replies

5. Shell Programming and Scripting

Need help in reading a file horizontally and printing vertically

Hi Every body, I have file which has enttries, with each 5 entries as a set of entries, I would like to read the file (line by line) and print five entries of a set vertically, the next entry should come in the next line. Example: cat sample_file I am a Unix Adminsitrator new to shell... (6 Replies)
Discussion started by: aruveiv
6 Replies

6. Solaris

0KB printing files

Hi, I am dealing with strange problem... whenever we use our software to trigger some printing files, along with that it generates lot of zero KB printing files, in our code base we generate a printing file only if its size is >0. So I suspect it could be something to do with printing level... (2 Replies)
Discussion started by: vivek.gkp
2 Replies

7. Shell Programming and Scripting

Reading and printing one by one contents of a file

I have a file which has following contents: localhost_IP_SIP_1233026552455.xml localhost_IP_SIP_1233026552460.xml localhost_IP_SIP_1233026552467.xml localhost_IP_SIP_1233026552759.xml localhost_IP_SIP_1233026552969.xml localhost_IP_SIP_1233026552975.xml ... (2 Replies)
Discussion started by: Aditya.Gurgaon
2 Replies

8. Shell Programming and Scripting

reading two files, comparing, printing when unmatched value is seen

Hello, I have two files: file1 1 2 3 4 5 file2 "a","b",,,,,"c","1",..... "s","d",,,,,"s","1",..... "a","c",,,,,"d","1",.... "f","v",,,,,,"f","2",..... etc I have to read "1" from file1 and grab all records in file2 (say column 6 in file2 is "1") until the column changes its value (... (6 Replies)
Discussion started by: i.scientist
6 Replies

9. UNIX for Dummies Questions & Answers

printing PDF files

Hi all: I'm trying to resolve a print issue in HPUX. Background: An ascii report file was being produced by a program. It was being sent to the printer via internal commands, to wit: let #send_status = 0 let $send_cmd = 'lp -d lp03 /ps/tmp/edsprint/eds*.N.LIS' call... (4 Replies)
Discussion started by: abNORMal
4 Replies

10. UNIX for Dummies Questions & Answers

Printing .TIFF files

Please forgive my ignorance...but I was hoping a Unix guru could help me with sending .TIFF files to an HP color laserjet 8550. I understand that .TIFF is not one of the languages used in this case, but I understood that there might be some commands that could be added to the queue to allow it to... (3 Replies)
Discussion started by: elbryan
3 Replies
Login or Register to Ask a Question