dasdasdasd
Review Request #3675 — Created Dec. 15, 2012 and updated
asdsad
assad
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<errno.h>
#define FILE_NAME "qas"
#define MAX_LINE 200
char* readLine(int);
int main(){
int fd;
int lineno = 1;
char *linebuf = NULL;
fd = open(FILE_NAME, O_RDONLY);
if(fd < 0) {
perror(FILE_NAME);
return -1;
}
while ((linebuf=readLine(fd)) != NULL ) {
printf(" %d: %s",lineno,linebuf);
lineno++;
free(linebuf);
}
return 0;
}
/* Funtn defntin of readlin() */
char* readLine(int fd) {
char *buffer;
buffer = NULL;
signed int i;
int n,k = 0;
buffer = (char*)malloc(1024);
for(i = 0;(n = read(fd,buffer+i,1)) > 0;i++) {
if(buffer[i] == ' ') {
k = k+1;
if(i == 0) { // to avoid space in first postn