heyy...

i need to analyse diffrent text(strings) inputs...
and there is no pattern between the inputs...
i have a question in my school...i need to do like a little storage with char**...and each time i get a string i need to input it into the char**, if the char** gets full, i need to get rid of the strings in the beggining of the char** and put new ones....
therefore, i have a countless index, and the problem is: when i get in the input !n (n= number of line to print, 123456....n)

i need some way to identify what is the n.....(in the !n if its 1 2 3 4 ...
so i can pull the line...

i was thinking about sscanf....but with which parameters insid of it??
how i cut the n? %s%d?

I had a rather hard time following what you were saying. Try posting some code(pseudo even).

What I got was: You have a char**, you fill it with input, after reaches its limits you begin to overwrite the initial positions, but somehow you have infinite limits and no way of tracking something and something.... I can't decipher.

That sounds like the classic circular array. The way I did it was to have two counters. The first counter indicates the maximum number of strings that can be put into the array (e.g. the array's allocated amount). The second counter indicates the next insertion position int nextpos; When nextpos == max then its time to wrap nextpos back to 0.

That sounds like the classic circular array. The way I did it was to have two counters. The first counter indicates the maximum number of strings that can be put into the array (e.g. the array's allocated amount). The second counter indicates the next insertion position int nextpos; When nextpos == max then its time to wrap nextpos back to 0.

yes that right!!!....i did it...
still i have this problem how i check if the input is !1 \ !2 \ !3...

I understood that you also wanted to know how to limit the input to a certain amount of characters. You should use

fgets(char* target, MAX_CHARS, stdin);

to do it.

Pattern matching is not that easy with C. Here is one approach though.

If there is some specific pattern to the input then you can check it using if else statements. For example if the input is

!1 \ !2 \ !3

You would say if the first char is a ! then proceed else fail. If you proceeded and then the second char is a digit then proceed.... You get the idea.

How ever if there is no specific pattern as such then you have to be very careful about what you will put in the if else conditions

Edited 6 Years Ago by abhimanipal: n/a

This article has been dead for over six months. Start a new discussion instead.