Help with UNIX more c code

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Help with UNIX more c code

 
0
  #1
Dec 3rd, 2004
Ok, for a lab I have to write the UNIX more filter in C, but I have got everything done execpt one thing. I only hvae it to where it can read 20 lines at a time. But what I want to do is if argv[1] == -Pxx where xx is the amount of lines you want to display at a time. but I need to use a scanf() and a atoi command I think but I have not idea on how to do that. Here is my code and where it sets the amount of line sto be printed is in bold.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

main(int argc, char *argv[])

{
int line_no = 0;
int i=1;
FILE *fp;
char ch;
int linec;
char line[256];

while ( i < argc )
{
if ( (fp = fopen(argv[i],"r")) != NULL )
{
printf("\n%s\n",argv[i]);
while(!feof(fp) )
{
line_no = (++line_no) % 20;
if ( line_no == 0 )
{
printf("---Press enter for more lines---");
if ( (ch = getchar()) == 'q')
exit(0);
}

if ( fgets(line, 255, fp) != NULL ) /* not eof on line */
printf("%s", line);
}
fclose(fp);
}

++i;
}
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with UNIX more c code

 
0
  #2
Dec 4th, 2004
read the parameter, strip away the -P, and use atoi on the rest of the string to convert it into an integer number.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Help with UNIX more c code

 
0
  #3
Dec 4th, 2004
could you right a peice of code for me that would do that for me please.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Help with UNIX more c code

 
0
  #4
Dec 5th, 2004
Originally Posted by jifiii
could you right a peice of code for me that would do that for me please.

He could, (heck I probably could), but how would you learn anything? Just take his instructions, and implement them the best way that you can think of. Then post that, and see what, if anything, we can suggest.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Help with UNIX more c code

 
0
  #5
Dec 5th, 2004
Ok, can you answer me this question how do you strip away the -P part.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with UNIX more c code

 
0
  #6
Dec 5th, 2004
there's a function to take a substring of a longer string. Find out what it is and how you use it.
Any manual, helpfile or other reference will tell you what to do.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 45
Reputation: jifiii is an unknown quantity at this point 
Solved Threads: 1
jifiii jifiii is offline Offline
Light Poster

Re: Help with UNIX more c code

 
0
  #7
Dec 5th, 2004
Where would I find that at, because I have the program form working except from inputing how many lines you want to display at a time.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help with UNIX more c code

 
0
  #8
Dec 6th, 2004
what did I say? Did you even bother to read past the first few words or are you too lazy even for that?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 12
Reputation: nvanevski is an unknown quantity at this point 
Solved Threads: 1
nvanevski nvanevski is offline Offline
Newbie Poster

Re: Help with UNIX more c code

 
0
  #9
Dec 6th, 2004
if you work on unix/linux, check the man page for getopt() function. It helps very much. At first it seems like an overhead, but in fact is very usefull.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2447 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC