/*Program starts*/ int main(int argc, char *argv[]) { int len; int max; char line[MAXLINE]; /*char longest_st[MAXLINE];*/ char longest[MAXLINE]; max = 0; while ((len = getline1(line, MAXLINE)) > 0) { if(len == MAXLINE - 1 && line[MAXLINE-2] != '\n') { while(getchar() != '\n') ++len; ++len; } if(len > max) { max = len; copy(longest, line); } } if(max > 0) printf("%s", longest); printf("\nLength: %d\n", max); /*Program ends*/ return 0; }
int main() { int in_comment,len; int in_quote; int t; in_comment = in_quote = t = 0; while ((len = getline1()) > 0 ) { t=0; while(t < len) { if( line[t] == '"') in_quote = 1; if( ! in_quote ) { if( line[t] == '/' && line[t+1] == '*') { t=t+2; in_comment = 1; } if( line[t] == '*' && line[t+1] == '/') { t=t+2; in_comment = 0; } if(in_comment == 1) { t++; } else { printf ("%c", line[t]); t++; } } else { printf ("%c", line[t]); t++; } } } return 0; }
// Save lines inputed in a pointer array and return number of lines int readlines(char *ptarr[],int maxlines, char *alloc) { int nlines,i; nlines = i = 0; int len; char line[MAXLENGTH]; char *p; p = alloc; while ((len=getline1(line, MAXLENGTH)) > 0) { // Check available in storage if (ALLOCSIZE - (strlen(alloc) + len) > 0) { line[len-1] = '\0'; strcp(p,line); } else { printf("Error: Not enough storage !!!!"); } nlines++; ptarr[i++] = p; p += len; } return nlines; }
void input(){ printf("enter row\n"); scanf("%d",&m); printf("enter col\n"); scanf("%d",&n); int i,j; a = (int**)malloc(sizeof(int*)*m); for(i = 0; i < m; i++) a[i] = (int*)malloc(sizeof(int)*n); for(i = 0; i < m; i++) for(j = 0; j < n; j++) a[i][j] = 0; c = (char**)malloc(sizeof(char*)*m); for(i = 0; i < m; i++) c[i] = (char*)malloc(sizeof(char)*n); int l; char line[100],ch; scanf("%c",&ch); for(i = 0; i < m; i++){ getline1(line,MAXLINE); linecopy1(line,c[i]); } }
main() { char line[MAXLINE]; //current input line char longest[MAXLINE];// = {65}; //longest line entered int len; //length of the current input line int max=0; //length of longest line while((len = getline1(line, MAXLINE)) > 0) { if(len > max) { max = len; copy(line, longest); } } if(max > 0) printf("\n\n%s", longest); /* int i; for(i=0; i<max; i++) printf("%c", longest[i]); printf("\n"); */ }
main() { int p; printf("enter a string of hexa decimal digits\n"); getline1(); p=htoi(); printf("decimal value=%d",p); }
int getch(void) /* get a (possibly pushed back) character */ { if(curbufsize >= curtotalbufsize) { curtotalbufsize = getline1(buf); curbufsize = 0; } return buf[curbufsize++]; }
main(int argc, char *argv[]) { // Steps to solve // 1. Identify loop to check, limited of the loop // 2. check argc > 0. // 3. int c, number = 0, except = 0, lineno = 0, found = 0; char line[MAXLINE]; // Assure loop run when argc always greater than 1. while (--argc > 0 && (*++argv)[0] == '-') { // Do something in loop. while (c = *++argv[0]) { switch (c) { case 'x': except = 1; break; case 'n': number = 1; break; default: printf("Illegal option %c\n",c); argc = 0; found = 0; break; } } } if (argc != 1) { printf("Usage: find -x -n pattern\n"); } // When the loop finished, argc = 1 else { //OK. Got right expression. Let to use something gain from loop. Present the result while (getline1(line,MAXLINE) > 0) { lineno++; if ((strstr(line,*argv) != NULL) != except) { if (number) // print number of lines. printf("%d: ",lineno); // print line printf("%s\n",line); found++; } } } return found; }
main() { extern double k; extern char s[lim]; printf("enter a string\n"); getline1(); printf("line entered=%s\n",s); k=atof(); printf("value =%f\n",k); }
int main() { int len; char line[MAXLINE]; while ((len = getline1(line, MAXLINE)) > 0) if (len > LIMIT) printf("%s", line); return 0; }
int main() { double sum,atof1(char[]); char line[MAXLINE]; sum=0; while(getline1(line,MAXLINE)>0) printf("\t%g\n",sum+=atof1(line)); return 0; }
int main() { int len; char line[MAX_LINE_NUM]; while((len = getline1(line, MAX_LINE_NUM)) > 0) { if(line[len - 1] == '\n') { line[len - 1] = '\0'; } reverse1(line); printf("reverse output:%s\n", line); } }
/* readlines: read input lines */ int readlines(char lijst[MAXLINES][MAXLEN], int maxlines) { int len, nlines; nlines = 0; while ((len = getline1(lijst[nlines], MAXLEN)) > 0) if (nlines >= maxlines) return -1; else lijst[nlines++][len-1] = '\0'; return nlines; }
int main(void) /* #define processor */ { int i, res, c; struct nlist *plist, *temp; char line[MAXLINE], word[MAXWORD], defnword[MAXDEFN], *name, *defn, *p, uchoice[MAXLINE]; while ((res = getword(word, MAXWORD)) != EOF) { if (res == '#') /* # received */ { if (getline1(line, MAXLINE) > 0) { p = line; while (*p == ' ' || *p == '\t') /* skip blanks */ p++; for (i = 0; *p != ' ' && *p != '\t' && *p != '\n'; p++, i++) /*see if 'define' */ word[i] = *p; word[i] = '\0'; if (strcmp(word, "define")) { putchar('#'); printf("%s", line); continue; } while (*p == ' ' || *p == '\t') /* skip blanks */ p++; for (i = 0; *p != ' ' && *p != '\t' && *p != '\n'; p++, i++) /*get name */ word[i] = *p; word[i] = '\0'; name = strdup1(word); } else /* if input not got properly */ return printf("error while processing...\n"); /* install */ { while(*p == ' ' || *p == '\t') /* skip blanks before defn */ p++; for (i = 0; *p != '\n' && *p != EOF; p++, i++) /* get defn */ defnword[i] = *p; defnword[i] = '\0'; defn = strdup1(defnword); install(name, defn); } } else if (isalpha(word[0])) if ((temp = lookup(word)) != NULL) printf("%s", temp->defn); else printf("%s", word); } return 0; }
int main(int argc, const char *argv[]) { char s[20]; printf("Input s: "); getline1(s, 20); squeeze(s, 'c'); printf("The result is %s", s); return 0; }
/* 找出所有的模式匹配的行 */ main() { char line[MAXLINE]; int found = 0; while(getline1(line, MAXLINE) > 0) if(strindex(line, pattern) >= 0) { printf("%s", line); found++; } return found; }
int main(int argc, const char *argv[]) { char line[MAXLINE]; int found = 0; while (getline1(line, MAXLINE) > 0) { if(strindex(line, pattern) >= 0) { printf("%s", line); found++; } } return found; }
main() { int i, len; char line[MAXLENGTH]; for (i = 0; (len = getline1(line, MAXLENGTH)) > 0; ++i) { detab(line, len); printf("%s", line); } return 0; }
int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; nlines = 0; while ((len = getline1(line, MAXLEN)) > 0) if (nlines >= maxlines || (p = alloc1(len)) == NULL) return -1; else { line[len-1] = '\0'; /* delete newline */ strcpy(p, line); lineptr[nlines++] = p; } return nlines; }
main() { int len; int max; char line[MAXLINE]; char longest[MAXLINE]; max = 0; while((len = getline1(line, MAXLINE)) > 0) if (len > max) { max = len; copy(longest, line); } if (max > 0) printf("%s", longest); return 0; }
int main(void) { int len, i; char line[1000]; while ((len = getline1(line)) > 0) { if (len > 1) { i = len - 1; while (line[i] == ' ' || line[i] == '\t' || line[i] == '\n') i--; line[++i] = '\n'; line[++i] = '\0'; printf("%s", line); } } return 0; }
int main() { int len, i, parentheses, brackets, braces; bool comment, squot, dquot; char line[MAXLINE]; comment = dquot = squot = false; parentheses = brackets = braces = 0; while ((len = getline1(line, MAXLINE)) > 0) { for (i = 0; i < len; i++) { if ((line[i] == '/') && (line[i+1] == '*') && !comment) comment = true; else if ((line[i] == '*') && (line[i+1] == '/') && comment) comment = false; else if ((line[i] == '(') && !comment) parentheses++; else if ((line[i] == ')') && !comment) parentheses--; else if ((line[i] == '[') && !comment) brackets++; else if ((line[i] == ']') && !comment) brackets--; else if ((line[i] == '{') && !comment) braces++; else if ((line[i] == '}') && !comment) braces--; else if ((line[i] == '\'') && !comment) squot = !squot; else if ((line[i] == '"') && !comment) dquot = !dquot; } } if (parentheses != 0) printf("Parenthesis missing\n"); if (brackets != 0) printf("Bracket missing\n"); if (braces != 0) printf("Brace missing\n"); if (dquot == true) printf("double quote missing\n"); if (squot == true) printf("single quote missing\n"); if (comment == true) printf("file ends inside comment\n"); return 0; }
/* reverse Polish calculator */ main() { int type; double op2; char s[MAXOP]; if(getline1(line,ALIMIT)==1) while ((type = getop(s)) != '\0') { switch (type) { case NUMBER: push(atof(s)); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '/': op2 = pop(); if (op2 != 0.0) push(pop() / op2); else printf("error: zero divisor\n"); break; case '%': op2=pop(); if(op2!=0.0) push(fmod(pop(), op2)); else printf("error :zero diviser\n"); break; case '\n': printf("\t%.8g\n", pop()); break; default: printf("error: unknown command %s\n", s); break; } } else printf("error:line full,can't get line!!\n"); return 0; }
main() { int len=0; int max; char line[MAXLINE]; char longest[MAXLINE]; while((len = getline1(line, MAXLINE)) > 0) {if (len > 8) { copy(longest, line); } } printf("\nThe lines that are longer than 8 characters"); printf("\n------------------------------------------"); printf("\n\n%s\n\n", longest); return 0; }
int main(int argc, char *argv[]) { int argument = 10; if (argc == 2) argument = abs(atoi(argv[1])); if (argument == 0) argument = 10; char currentline[500]; init_lineholder(argument); while (getline1(currentline) > 0) { insert_line(currentline); } print_lines(); }
main() { char linebuffer[MAXINPUT]; int linebuffersize = 0; char line[MAXINPUT]; int linesize = 0; while( (linesize = getline1(line, MAXINPUT)) > 0 ) { if(linesize > LINEMAX) { linesize = validateline(line, linesize); linebuffersize = stradd(line, linebuffer, linebuffersize); } } printf("%sBuffer=%d\n", linebuffer, linebuffersize); }
main() { char line[MAXLINE]; //current input line int len, i; //length of the current input line while((len = getline1(line, MAXLINE)) > 0) { //len = 1 when line is empty ('\n'), len = 0 when EOF for(i=len-2; line[i] == ' ' || line[i] == '\t' || line[i] == '\n'; i--) { line[i] = '\0'; //if the char before NULL is space or newline, replace it with NULL, decrement i } if(i > 0) printf("%s\n", line); } }
int main() { int c; char ch; int j; char str[10]; int ret = 0; while (gi < MAX) { printf ("enter your choice\n\n"); printf ("D or dfor display\n\n"); printf ("I or ifor insert a line\n"); printf ("s or S for search\n\n"); scanf ("%c", &ch); switch(ch) { case 'd': case 'D': for (j = 0; j < gi; j++) printf ("%s\n", array[j]); break; case 'i': case 'I': getline1(&array[gi++]); break; case 's': case 'S': printf ("enter the string"); scanf ("%s", str); ret = grep(array, str); if(ret) printf("string found at line no %d \n", ret); else printf ("string not found\n"); break; default: continue; } } }
main() { printf("Pls, input...... \n"); int i,j,len,index,nspaces,c; char bufferline[MAXLINE], buffer[MAXLINE]; i = j = index = 0; // Index is used to count only characters that are not \n, \t while ((len = getline1(bufferline,MAXLINE)) > 0) { i = 0; while ((c = bufferline[i++]) != '\0' && c != '\n') { if (c == '\t') { nspaces = count_available_spaces(index); // Insert properly spaces (or detab) to buffer array while (nspaces-- > 0) { buffer[j++] = ' '; ++index; } } else { // Calculate number of available spaces need to write char buffer[j++] = c; ++index; } } // Because new line is not a character so space calculating is not correct // How can i solve this ? I must insert n to buffer but exclude n when need to calculate spacing. // That mean must have a number to count character, this number depend on index. So index must be reset in the new line :) if (c == '\n') { buffer[j++] = '\n'; index = 0;// reset indexing } } // Finally, insert end of line to buffer of lines buffer[j] = '\0'; printf("Run detab program ............\n%s\n",buffer); }
int getlines(char *lineptr[], int maxlines) { int len; int nlines = 0; char line[LINESIZE]; char *p = NULL; while((len = getline1(line, LINESIZE)) > 0) { if (nlines >= maxlines || (p = alloc(len)) == NULL) { return -1; } else { line[len-1] = '\0'; strcpy(p, line); lineptr[nlines++] = p; } } return nlines; }