Author Topic: C Problem| If your good at C please help me.  (Read 2968 times)

0 Members and 1 Guest are viewing this topic.

Offline MikeGT

  • Posts: 406
    • View Profile
C Problem| If your good at C please help me.
« on: January 23, 2014, 10:39:34 am »
Hello guys, i'm having a bit of a trouble getting a program to work.
The main idea is this.

-Program needs to be written in C.
-Program needs to open a file.
-Ask for 2 keywords... and read the info in the file in the middle of the 2 keywords.

If anyone of you are good at C and can help me i would thanks you...

Love Mike.

Offline [MAF]Karlis

Re: C Problem| If your good at C please help me.
« Reply #1 on: January 23, 2014, 11:55:55 am »
could you show what have you done first, so we don't end up just doing your homework?

Offline MikeGT

  • Posts: 406
    • View Profile
Re: C Problem| If your good at C please help me.
« Reply #2 on: January 23, 2014, 12:29:03 pm »
it's a work i have to do untill midnight today... i'm having a bit of trouble... my friend did an huge program that does not work... i'm trying to go step by step right now...


#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="This is a simple string";
 
  char * p1,* p2;

  p1 = strstr(str,"is");
  p2 = strstr(str,"string");

 
  puts (str);
  system("Pause");
  return 0;
}

how can i read the string from "is" to "string" ?

Offline [MAF]Karlis

Re: C Problem| If your good at C please help me.
« Reply #3 on: January 23, 2014, 12:43:36 pm »
you will have to make a int stringfind(char * srt, char * match_str) function, because C standard library doesn't have one afaik.
it should loop trough the given str and try to match 1st char of match_str.
if it matches, check next characters in the match, if they do not match, reset match_str index from the beginning.
if it matches for the whole length of match, return the position that you found the first char to be at.
if it still didn't match in the end, return 0.

once that is done, get the position of first and second word, add/substract length of the words from the positions, and pick everything in between.