| | |
Help with UNIX more c code
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 45
Reputation:
Solved Threads: 1
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;
}
}
#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;
}
}
•
•
•
•
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
![]() |
Similar Threads
- Unix compiler/code tags help with mac os x (Shell Scripting)
- Run Unix Find command using java Program (Java)
- How to Pass new argument to running process in unix with out interrupt (C)
- News Story: SCO Doesn't Own UNIX - Someone Please Tell SCO (Linux Servers and Apache)
- News Story: OS wars over as Leopard mauls Vista (Windows Vista and Windows 7)
- Porting Unix code (32bit machine) to Linux (64bit machine) (C)
Other Threads in the C Forum
- Previous Thread: mode prog in c
- Next Thread: Draw sin curve w/ user input, how to code sin()?
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






