GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jan-2005, 08:07
Benayoun Benayoun is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Benayoun is on a distinguished road

need help - questions about strings


in C:

i cant use string.h

1) i need to write function that gets 2 strings and searcg for the longest mini string that appear in the 2 strings.
the function will write the mini string to a new string
and return ger length


2) i need to write function that get s 2 strings. if thay are equal the function will return 0. otherwise return -1, but there is no different between capital letters and small letters.
exaple: For BOB and Bob return 0

3) i need to write a function that gets a string and a word. the function return how many times the word appear in the string. thw words in the strings separate by any sign that is not a letter. thare is no differnet between Caputal and small letters.
example :
string :
One,two-onton;one,three.ONE'TWO.Two-four\one
word:
One

the function return 4

10x
  #2  
Old 21-Jan-2005, 10:42
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Benayoun
in C:

i cant use string.h



10x


Using string.h is easy. Just put this near the beginning of your program file:

CPP / C++ / C Code:
#include <string.h>

Now, if your question is about how to use some of the functions declared in string.h to perform your assigned tasks, look for a reference in your text book, class notes, or whatever. You can use a search engine to find information. (Just to get you started, one link that I found is http://www.cplusplus.com/ref/cstring/).

This describes the functionality of functions such as strcmp(), strcpy(), strcat(), strstr(), etc.

If you try to do something and it doesn't work the way you think it should, post the code that shows what you are attempting.

Tell us what you got, what you expected to get, specifically what you don't understand, etc.

Tell us what compiler and operating system you are using (sometimes it matters).

Regards,

Dave
  #3  
Old 21-Jan-2005, 12:11
Benayoun Benayoun is offline
New Member
 
Join Date: Jan 2005
Posts: 2
Benayoun is on a distinguished road

you didnt understand me


you didnt understand me

i cant use string.h
iknow how to use it
but the instructions say that i can use inly stdio.h
  #4  
Old 21-Jan-2005, 12:29
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Benayoun
you didnt understand me

i cant use string.h
iknow how to use it
but the instructions say that i can use inly stdio.h

I'm sorry that I didn't understand what you were asking for.

[edit]
Come to think about it, you didn't actually ask a question. I was just guessing. And I'm still just guessing that you want some help in fulfilling your assignment.
[/edit]

If you know how to use the standard library string manipulation functions, write a program using functions like strcat(), strcpy(), strcmp(), etc. Test the program(s) with whatever inputs you want to apply.

Then, one at a time, implement your own version of the functions and plug them into your test program.

Show us what you have so far, and ask specific questions.

Regards,

Dave
Last edited by davekw7x : 21-Jan-2005 at 13:05.
  #5  
Old 23-Jan-2005, 19:05
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
Are you saying that you are not allowed to use string.h in your program, instead your only allowed to use stdio.h? If that is the case your program is going to be a bit larger.


1)You could always use arrays. It would be ackward and take a bit of programming but you coudl always have a bunch of character arrays and use those instead of strings. You'd need two temp arrays. fill the first one with the first mini string, second one with the second mini string. Have two counters that tract the amount of characters that go into each string. Which everyone has the highest amount you keep. The other one you simply overwrite and reset the counter. Just keep this up untill you hit the end of your array. The string in question will be in the larger of your temp arrays.

2)No ideal how to do this with out string compare unless you know there size already. Then its simply comparing array1[x] to array2[x], where x is whatever index number.

3)You'd have to do something simular to what i said in responce to number 1.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
  #6  
Old 24-Jan-2005, 00:59
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by dabigmooish
... you coudl always have a bunch of character arrays and use those instead of strings.
FYI, in C (the language Benayoun is using) there is no difference between strings and character arrays. They are identical, unless you consider the final null to be a difference. I don't. All 'strings' end with a null, and most 'character arrays' do too.
__________________

Age is unimportant -- except in cheese
  #7  
Old 24-Jan-2005, 02:15
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
I find it easier to think of arrays and strings as differnt, especially since strings.h is not to be used. By saying they are an array of characters and not strings, you don't need to remember that pesky null terminator too.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
array of pointers to strings mirizar C++ Forum 5 21-Jan-2005 10:24
C++ style strings and STL dexter C++ Forum 14 04-Jan-2005 07:46
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38
I am reviewing Arrays and need help converting some strings to arrays jenmaz C Programming Language 22 22-Nov-2004 23:26
comparing strings yarons C Programming Language 6 19-Oct-2004 21:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:54.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.