#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
int getline(char line[], int max)
int strindex(char source[], char searchfor[]);
char pattern[] = "ould"; /* pattern to search for */
/* find all lines matching pattern */
main()
{
char line[MAXLINE];
int found = 0;
while (getline(line, MAXLINE) > 0)
if (strindex(line, pattern) >= 0) {
printf("%s", line);
found++;
}
return found;
}
/* getline: get line into s, return length */
int getline(char s[], int lim)
{
int c, i;
i = 0;
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
s[i++] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* strindex: return index of t in s, -1 if none */
int strindex(char s[], char t[])
{
int i, j, k;
for (i = 0; s[i] != '\0'; i++) {
for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++)
;
if (k > 0 && t[k] == '\0')
return i;
}
return -1;
}
int getline(char line[], int max);
int strindex(char source[], char searchfor[]);
/* getline: get line into s, return length */
int getline(char s[], int lim)
{
int c, i;
i = 0;
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
s[i++] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* strindex: return index of t in s, -1 if none */
int strindex(char s[], char t[])
{
int i, j, k;
for (i = 0; s[i] != '\0'; i++) {
for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++)
;
if (k > 0 && t[k] == '\0')
return i;
}
return -1;
}
#include <stdio.h>
[sathish@localhost ~]$ gcc funckr.c
funckr.c: In function ‘gettline’:
funckr.c:7:4: error: parameter ‘pattern’ is initialized
char pattern[] = "ould"; /* pattern to search for */
^
funckr.c:10:4: error: expected declaration specifiers before ‘main’
main()
^
funckr.c:26:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
funckr.c:42:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
funckr.c:4:8: error: old-style parameter declarations in prototyped function definition
int gettline(char line[], int max)
^
funckr.c:52:4: error: expected ‘{’ at end of input
}
int getline(char line[], int max)[COLOR="#FF0000"];[/COLOR]
int strindex(char source[], char searchfor[]);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include <stdio.h> #define MAXLINE 1000 /* maximum input line length */ int getline(char*, int); int strindex(char*, char*); char pattern[] = "ould"; /* pattern to search for */ /* find all lines matching pattern */ int main() { char line[MAXLINE]; int found = 0; while (getline(line, MAXLINE) > 0) if (strindex(line, pattern) >= 0) { printf("%s", line); found++; } printf("%d",found); } /* getline: get line into s, return length */ int getline(char s[], int lim) { int c, i; i = 0; do{ c = getche(); s[i++] = c; } while (--lim > 0 && c != EOF && c != '\r'); s[i] = '\0'; return i; } /* strindex: return index of t in s, -1 if none */ int strindex(char s[], char t[]) { int i, j, k; for (i = 0; s[i] != '\0'; i++) { for (j=i, k=0; t[k]!='\0' && s[j]==t[k]; j++, k++) ; if (k > 0 && t[k] == '\0') return i; } return -1; }
Is there a getline function, I think it was gets() in stdio.h.. The above program compiles in the dev c++...getline is a pre-defined C function declared in the stdio.h header file. Change your function name to something else and then it will compile without any errors.
extern _IO_ssize_t getline (char **__restrict __lineptr,
size_t *__restrict __n,
FILE *__restrict __stream) __wur;
#include<stdio.h>
void main()
{
int *j,i=4;
j=i*2;
printf("j=%d\n",j);
}
[sathish@localhost ~]$ gcc pointest15.c
pointest15.c: In function ‘main’:
pointest15.c:5:2: warning: assignment makes pointer from integer without a cast [enabled by default]
j=i*2;
#include<stdio.h>
float a=3.14;
float **z;
float **y;
float ***x;
float ****v;
float ****w;
float **fun1(float*);
float ****fun2(float***);
void main()
{
z=fun1(&a);
printf("%u %f\n",z,**z);
}
float **fun1(float *z)
{
y=&z;
v=fun2(&y);
return (**v);
}
float ****fun2(float ***x)
{
w=&x;
return (w);
}
2) please explain the below program .and also give me links for clear explanation about pointers,pointers in array ,pointers in strings and data structures...
Code:#include<stdio.h> void main() { int *j,i=4; j=i*2; printf("j=%d\n",j); }
Code C - [expand] 1 2 3 4 5 6 7 8 #include<stdio.h> void main() { int *j, i = 4, x; j = &x; // A pointer shd be initialized before used *j= i*2; // you cant assign a integer variable to a pointer printf(" j = %x\n *j = %d\n", j , *j); }
2) please explain the below program .and also give me links for clear explanation about pointers,pointers in array ,pointers in strings and data structures...
error message when executing...Code:#include<stdio.h> void main() { int *j,i=4; j=i*2; printf("j=%d\n",j); }
- - - Updated - - -
3) explain the below program
Code:#include<stdio.h> float a=3.14; float **z; float **y; float ***x; float ****v; float ****w; float **fun1(float*); float ****fun2(float***); void main() { z=fun1(&a); printf("%u %f\n",z,**z); } float **fun1(float *z) { y=&z; v=fun2(&y); return (**v); } float ****fun2(float ***x) { w=&x; return (w); }
#include<stdio.h>
void main()
{
int *j,i=4;
j= &i;
*j = *j*2;
printf("j=%d\n",*j);
}
#include<stdio.h>
void display(int *,int,int);
void show(int (*q)[4],int,int);
void print(int q[][4],int,int);
void main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,0,1,6};
display(a,3,4);
show(a,3,4);
print(a,3,4);
}
void display(int *q,int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
printf("%d",*(q+i*col+j));
printf("\n");
}
printf("\n");
}
void show(int (*q)[4],int row,int col)
{
int i,j;
int *p;
for(i=0;i<row;i++)
{
p=q+i;
for(j=0;j<col;j++)
printf("%d",*(p+j));
printf("\n");
}
printf("\n");
}
void print (int q[][4],int row,int col)
{
int i,j;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
printf("%d",q[i][j]);
printf("\n");
}
printf("\n");
}
parrayy25.c: In function ‘main’:
parrayy25.c:8:1: warning: passing argument 1 of ‘display’ from incompatible pointer type [enabled by default]
display(a,3,4);
^
parrayy25.c:2:6: note: expected ‘int *’ but argument is of type ‘int (*)[4]’
void display(int *,int,int);
^
parrayy25.c: In function ‘show’:
parrayy25.c:30:3: warning: assignment from incompatible pointer type [enabled by default]
p=q+i;
Code C - [expand] 1 display(a,3,4);
Code C - [expand] 1 display(&a,3,4);
Code C - [expand] 1 void show(int (*q)[4],int row,int col)
Code C - [expand] 1 void show(int *q[4],int row,int col)
Code C - [expand] 1 p=q+i;
Code C - [expand] 1 *p=q+i;
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include<stdio.h> void display(int *,int,int); void show(int (*q)[4],int,int); void print(int q[][4],int,int); void main() { int a[3][4]={1,2,3,4,5,6,7,8,9,0,1,6}; display((int*)a,3,4); show(a,3,4); print(a,3,4); getch(); } void display(int *q,int row,int col) { int i,j; for(i=0;i<row;i++) { for(j=0;j<col;j++) printf("%d",*(q+i*col+j)); printf("\n"); } printf("\n"); } void show(int (*q)[4],int row,int col) { int i,j; int *p; for(i=0;i<row;i++) { p=(int*)q+i; for(j=0;j<col;j++) printf("%d",*(p+j)); printf("\n"); } printf("\n"); } void print (int q[][4],int row,int col) { int i,j; for(i=0;i<row;i++) { for(j=0;j<col;j++) printf("%d",q[i][j]); printf("\n"); } printf("\n"); }
Code C - [expand] 1 p=(int*)q+i;
#include<stdio.h>
# define ROW 3
#define COL 4
void main()
{
int i,j;
int (*b)[COL];
int *p;
b=fun2();
printf("array of b[][] in main\n");
for (i=0;i<ROW;i++)
{
p=(int*)b+i;
for (j=0;j<COL;j++)
{
printf("fun a%d",*(p+j));
}
printf("\n");
}
}
int (*fun2())[COL]
{
static int b[ROW][COL]={1,2,3,4,5,6,7,8,9,0,1,6};
int i,j;
printf("array a[][] in fun\n");
for(i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
printf("%d",b[i][j]);
printf("\n");
}
return b;
}
[sathish@localhost ~]$ gcc parray28.2.c
parray28.2.c: In function ‘main’:
parray28.2.c:10:2: warning: assignment makes pointer from integer without a cast [enabled by default]
b=fun2();
^
parray28.2.c: At top level:
parray28.2.c:22:7: error: conflicting types for ‘fun2’
int (*fun2())[COL]
^
parray28.2.c:10:3: note: previous implicit declaration of ‘fun2’ was here
b=fun2();
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?