![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Nov 2005
Posts: 1
OS: xp
|
need desperate help on c++... please
Hello there.
im a young newb who is learning the c++ programming this year. i was given a specific task to do but then its really really hard for me. i have never learnt bout this before and its giving me a pain in the ***. i also have "c++ how to program", and spent like 2 days reading it but it seems like i can't use the principles from the book to solve teh tasks... it would be so generous of you if u could help me out on this task and simply explain why its like that after if u wish.. the task is that i hv to write a c++ prog (source) that asks for an arbitrary no. of input strings n a search pattern. then it outputs the no. of strings that match the search pattern and the matched strings. this is an eg of the behaviour of the prog. csh> ./ex3 Input string (enter X to stop): Imagine there's no heaven Input string (enter X to stop): It's easy if you try Input string (enter X to stop): No hell below us Input string (enter X to stop): Imagine there's no countries Input string (enter X to stop): You may say I'm a dreamer Input string (enter X to stop): But I'm not the only one Input string (enter X to stop): X Search pattern: no Number of matched strings: 3 Imagine there's no heaven Imagine there's no countries But I'm not the only one thats the behavour the prog should be like... the user enters any no. of strings until there is a single X input. the prog would search each input string and see if any of htem contains the search pattern. the search is by default case sensitive. teh two things that should be out-putted is the no of matched strings and all the matched strings in teh same order of the input... I would appreciate it so much if you could help me learn make this prog.... i hv been spending like few entire days on this but i really relaly can't get it... thank you so much,.... |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Manager, Networking Forums
Join Date: Sep 2002
Location: S.E. Pennsylvania, US
Posts: 41,720
OS: Windows 7, XP-Pro, Vista, Linux
Blog Entries: 1
|
Why don't you start by doing a simple flowchart of you you think the program should work? You won't learn anything if someone codes it up for you.
__________________
If TSF has helped you, Tell us about it! or Donate to help keep the site up! Microsoft MVP - Windows Desktop Experience |
|
|
|
|
|
#3 (permalink) |
|
Registered User
|
I was trying to code something up for this and it seems my old trick of:
char *var[10]; isnt working like i used to use it. If I could get the array elements to fill correct then it would work. Heres the code i came up with Code:
#include <iostream.h>
#include <conio.h>
#include <string.h>
int main()
{
int x = 0,y=0,total;
char ans[100];
char *al[100];
char pattern[100];
char *match[100];
while (true)
{
cout << "Input string (enter X to stop): ";
cin.getline(ans,100);
if (ans[0] == 'X' && ans[1] == '\0')
break;
/*THIS IS WHAT MESSES UP */
al[x] = ans;
/* DAMN YOU ^^ */
x++;
}
total = x;
cout << "Search String: ";
cin >> pattern;
for (x=0;x<total;x++)
{
if (strstr(al[x],pattern))
{
match[y] = al[x];
y++;
}
}
total = y;
cout << "Number of matches: " << total << endl;
for(x=0;x<=total;x++)
{
cout << match[x] << endl;
}
getch();
return 0;
}
__________________
My new homepage: |
|
|
|
|
|
#4 (permalink) |
|
Manager, Networking Forums
Join Date: Sep 2002
Location: S.E. Pennsylvania, US
Posts: 41,720
OS: Windows 7, XP-Pro, Vista, Linux
Blog Entries: 1
|
I don't doubt that the line:
al[x] = ans; is a problem! First off, you're attempting to use an unitialized pointer. You need to allocate memory for those strings, not just pointers.
__________________
If TSF has helped you, Tell us about it! or Donate to help keep the site up! Microsoft MVP - Windows Desktop Experience |
|
|
|
![]() |
| Thread Tools | |
|
|