|
I have to implement a string search in an excel file. can I some examples regarding this.
S.Yamni
|
|
|
|
|
What sort of search you require, explain a bit. then i am ready to
give you the sample or how to do it.
|
|
|
|
|
CString str;
char ch[6];
str="yamini";
ch=str;
In this I am trying to transfer the string in str to ch buffer.
S.Yamini
|
|
|
|
|
CString str;
char ch[6];
str="yamini";
ch=str;
strcpy(ch, str.GetBuffer(str.GetLength()) ); //Use this to cpy to buffer //Check the length
//or if u have ch as char* ch
//then ch = str.GetBuffer(0); //This code just points does not give a copy
//Let the allocation be dynamic
|
|
|
|
|
This works great.Thanks. I want to learn automation inVC++. Can u plz suggest some links or books.
S.Yamini
|
|
|
|
|
hi,
I am trying to develop a programme to let the user key in their name, then compare their name to the input file i have created using a notepad.
Can anyone suggest me how to check the name key in by the user to the names in the input file?If the name input were the 20th name, then how do i find it from the list? Do i need to use looping?
Another thing if i were to set let say in the same name list, for the first 5 person they need to do certain experiment. For the next 5 they need to do another different one. Then how do i do that?
The programme which i am trying to develop is some sort like a programme to identify the user and hence tell them what class do they need to attend,when,where.
THANKS.
-- modified at 9:10 Tuesday 3rd April, 2007
|
|
|
|
|
tanchinchee wrote: Can anyone suggest me how to check the name key in by the user to the names in the input file?
I don't see clearly the problem but wouldn't strcmp[^] work ? You just have to compare the strings, right ?
|
|
|
|
|
I have used strcmp before this. But let say i have 20 names in my list and the name input is the 20th name. i don't know how to search for it in the list. I can only obtain the first name from the list. Do i need to use looping? If yes how do i do it? And what is the use of the command EOF(End Of File)? Can you show me how to use it if it might be applicable in my project. Thanks.
p/s: Sorry i might not know many things as i am a beginner. But thanks for the help. Thanks...
|
|
|
|
|
Well, the problem is in fact not a single problem: you are asking quite different things so let's decompose everything.
In general, the best way to deal with these kind of situations (meaning, you have a file containing information that you need to access 'often) is to read the file once and store everything in memory.
1) How to store the data in memory ?
It looks like you have an undefined amount of data (names in your case) to read from the file. So we will need a kind of array to store this information. Two options: either you use the standard C++ arrays (using new[] operator) or you use a container class from the STL. I suggest the container from the STL: it is much more powerfull and flexible (and does all the memory management for you) but if you are a beginner, it might a little bit tricky at the begining (hopefully, there are quite a lot of tutorials). I recommand using the std::list in your case. Here[^] is a tutorial for example, but using google you can find a lot. Honnestly, it is worth the time to learn how to use it, you'll see in the future that it is very very helpfull.
What you could do is to have a structure for each entry of your file (that contains all the info about one person). Then use a std::list of these structures.
2) How to read data from the file ?
Now that you know how to store data in memory (more or less at least), you will need to read your data from the file. Here, it is difficult to help because I have absolutely no idea of how the data is formated in your file. If you could post a short example of the file it would be helpfull.
But again, you read each entrey one by one and for each of them, you fill a structure (the one explained in point 1) and you add it in your list. You continue until you reach the end of your file (EOF).
3) How to retrieve data from your list ?
That's not very difficult once you are familiar with the std::list. You can simply loop through your list until you find the information that you need.
Also, what you could do is using a std::map instead. It store in fact the data with a certain key so that you can easily find it afterward (with only the key).
Hope that helps, it is quite a broad subject so it is too long to enter in the details. You'll need to work a little bit by yourself.
|
|
|
|
|
Well, that's quite some useful information. Following is the example of list in my programme :
I have an infile("C:\\test.txt")
the infile looks like this:
No Name Student id
1. Tan Chin Chee AD051810
2. Lim AD051819
3. Daniel AD051010
Well, how do i find the name Daniel and view which class does he need to attend?
(Lets say the first person needs to attend a Dynamics class, the second needs to attend a Thermo class while the third one needs to attend a Math class)
I am also facing a problem where i do not know how to set a different situation(to attend which class) for each person in the same list. Do i use looping as well?
|
|
|
|
|
tanchinchee wrote: 1. Tan Chin Chee AD051810
This will be a problem to handle: you have three words (they are separated by a white space) for the name...
Maybe what you could use to encode your data is xml, so your file will look like this:
<list>
<student Name="Tan Chin Chee" Id="AD051810">
<AttendingClass Name="Dynamics">
<AttendingClass Name="Thermo">
</student>
...
</list>
This will make things much more easier and you will be able to add things quite easily (like schedules for the classes or other information about your student). But of course, this will require to understand a little bit how xml works (but for these kind of things it is really really easy).
If you choose to use xml, you can find here[^] a nice xml parser.
|
|
|
|
|
Another thing. I have been trying to use the following source code to compare the input name from the user to the name store in the database but fail. Can i know what is the problem?
#include <iostream>
#include <fstream>
#include <cstring>
void main()
{
char n1[20],n2[20];
cin>>n1;
ifstream infile("C:\\test.txt");
infile>>n2;
while(n1!=n2)
{
infile>>n2;
if(strcmp(n1,n2))
cout<<"False";
else
cout<<"True";
}
}
Well, it turns out to be an infinite loop. Why is that? And how do i change it?
|
|
|
|
|
tanchinchee wrote: Well, it turns out to be an infinite loop.
Yes, that's normal. Simply because of that:
while(n1!=n2)
What you are comparing there is two pointers (you don't compare the contents of the string but the pointers). These pointers will always point to a different address, even if the two contents are the same.
You need to compare the strings, not the addresses:
while(strcmp(n1,n2))
But as you are already doing that inside the loop, it would be better to rewrite the loop in such way:
while(strcmp(n1,n2))<br />
{<br />
cout << "false";<br />
infile>>n2;<br />
}<br />
cout << "true";
In fact, you will only print true when the two strings are the same so when you exit the loop.
By the way, when you post code, use the pre or code tags (just above the emoticons).
|
|
|
|
|
why no one is answering for the threads posted. since last week i am not getting a good response. pls help me i am need guidance for tree control. i am new to this.
-- modified at 1:51 Monday 2nd April, 2007
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
|
Thanks Mr.Sky . i need some advice on creating an application that looks'n feel like windows explorer:
-one CTreeCtrl in left side of the dialog
-if we select one item in the tree it have to list the contents of a folder
-Data displayed in CTreeCtrl are files and directories
pls help me i need it now
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
Hope I understood your question
I think it will be easy for you I wrote like your question for show images (in the continue with you you need to a CListCtrl)your answer is exist on the codeproject but on the different articles(See Folder/File section and CTreeCtrl section);)
|
|
|
|
|
yes but till now noone gave me the idea to create the window. i dont want the code to written by someone. i just need the guidance
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
You can see these articles for help
|
|
|
|
|
|
You can find these articles on the Folder/File section and CTreeCtrl section
|
|
|
|
|
deeps_cute wrote: -one CTreeCtrl in left side of the dialog
-if we select one item in the tree it have to list the contents of a folder
my general idea would be look at CTreeCtrl Class and CFindFile class
|
|
|
|
|
Probably because you don't seem to be putting in any effort yourself - you seem to want someone here to write your program for you.
In one of your earlier posts someone pointed you to the TreeControl section of codeproject. A quick check shows
PathPicker[^]
that seems to have all the functionality you need for the tree control. There may be other ways to start - it's your program after all.
If you tried to get PathPicker going with an associated listbox that you fill with the contents of the directory you choose, and when you have specifc problems come back and ask, I'm sure you will get an answer.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Dear all.
Now I doing a project with MFC, so I would like ask you how to call child frame with any location (x, y) in the Main frame. Notice that when I called the child frame No.1, it locates at the left corner of Main frame and when I continue to call the child frame No.2, it appears at the same location of child frame No.2. Thank in advance all.
|
|
|
|
|
What about SetWindowPos ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|