** Open a file and read every word that contains an 'a'.
int main()
{
int count = 0;
char data[256];
FILE *f = fopen("file.txt", "r");
if (f) while (scanf("%s", data)) count += tolower(*data)=='a';
printf("%d words beginning with a ", count);
fclose(f);
}
** Write a binary search algorithm.
int binsearch(int t[], int v, int imin, int imax)
{
while (imax>=imin)
{
int imid = (max+min)/2;
if (t[imid]==v) return imid;
if (t[imid]>v) imax=imid-1; else imin=imid+1;
}
return -1;
}
** Insert a number into a linked list in ascending order
void insert(Node **node, int v)
{
Node *tmp = (Node *)malloc(sizeof(Node));
while(*node && (*node)->value>v) node = &(*node)->next;
tmp->value = v;
tmp->next = *node;
*node = tmp;
}
int main()
{
int count = 0;
char data[256];
FILE *f = fopen("file.txt", "r");
if (f) while (scanf("%s", data)) count += tolower(*data)=='a';
printf("%d words beginning with a ", count);
fclose(f);
}
** Write a binary search algorithm.
int binsearch(int t[], int v, int imin, int imax)
{
while (imax>=imin)
{
int imid = (max+min)/2;
if (t[imid]==v) return imid;
if (t[imid]>v) imax=imid-1; else imin=imid+1;
}
return -1;
}
** Insert a number into a linked list in ascending order
void insert(Node **node, int v)
{
Node *tmp = (Node *)malloc(sizeof(Node));
while(*node && (*node)->value>v) node = &(*node)->next;
tmp->value = v;
tmp->next = *node;
*node = tmp;
}