Example #1
0
int main(){
  // move ptr to index where sub is found
  ptr = strstr(string, sub1);
  // print
  printf("ptr value is: %s\n", ptr);
  printf("ptr is now pointing at char %c\n", *ptr);
  printf("ka in nsukami, index is %i\n", stringindex(string, sub1));

  // there is no ki inside nsukami, ptr will be null
  ptr = strstr(string, sub2);
  printf("ptr value is now: %s\n", ptr);
  printf("ki in nsukami, index is %i\n", stringindex(string, sub2));
  printf("ka in nsukami, index is %i\n\n", stringindex(string, sub1));

  // test for multiple matches, set array containing all indexes
  stringindex2("kamikazeka", "ka");

  // print all the indexes where pattern found
  // printf("ka in kamikazeka, indexes are:\n");
  // for(; nbr_found-- != 0 ; )
  //   printf("%i\n", indexes[nbr_found]);

  ptr2 = indexes;

  printf("using ptr ka in kamikazeka, indexes are:\n");
  for(; nbr_found-- != 0; )
    printf("%i\n", *ptr2++);

  // array of char where I'll store my input
  char line[SIZE];
  // increment this value if pattern found in my input
  int found = 0;

  // ask user for input
  while(getLine(line, SIZE) > 0) {
    // check if pattern found inside input
    if(stringindex(line, pattern) >= 0){
      printf("pattern '%s' found at index '%s'\n", pattern, line);
      found++;
    }
    else
      printf("pattern '%s', not found inside input '%s'\n", pattern, line);
    return found;
  }

  return 0;
}
Example #2
0
File: tsort.c Project: 8l/FUZIX
/*	the first for loop reads in the graph,
 *	the second prints out the ordering
*/
int main(int argc, const char *argv[])
{
	register struct predlist *t;
	FILE *input = stdin;
	register struct nodelist *i, *j;
	int x;
	char precedes[50], follows[50];
	if (argc > 1) {
		input = fopen(argv[1], "r");
		if (input == NULL)
			error("cannot open ", argv[1]);
	}
	for (;;) {
		x = fscanf(input, "%s%s", precedes, follows);
		if (x == EOF)
			break;
		if (x != 2)
			error("odd data", empty);
		i = stringindex(precedes);
		j = stringindex(follows);
		if (i == j || present(i, j))
			continue;
		t = (struct predlist *) malloc(sizeof(struct predlist));
		t->nextpred = j->inedges;
		t->pred = i;
		j->inedges = t;
	}
	for (;;) {
		x = 0;		/*anything LIVE on this sweep? */
		for (i = &firstnode; i->nextnode != NULL; i = i->nextnode) {
			if (i->live == LIVE) {
				x = 1;
				if (!anypred(i))
					break;
			}
		}
		if (x == 0)
			break;
		if (i->nextnode == NULL)
			i = findloop();
		printf("%s\n", i->name);
		i->live = DEAD;
	}
}