| | |
csv problem
![]() |
In your example if you enter "205" you will get nothing because there are no lines that contain "205"
But I understand what you mean anyway.
>>pls include the codes
Please first post your code to show us the effort you are making to solve the problem.
I would read the file one line at a time using fgets() function. Then you can use either strstr() to see if the line contains the search string, such as "205" and if it exists print the remainder of the line.
Code the problem one small step at a time to help from getting overwhelmed with the assignment. First, write the program that just opens the file. Get that to compile and work correctly. Then add to it the code needed to read each line using fgets(). Once that works you can continue with the reset of the assignment.
But I understand what you mean anyway.>>pls include the codes
Please first post your code to show us the effort you are making to solve the problem.
I would read the file one line at a time using fgets() function. Then you can use either strstr() to see if the line contains the search string, such as "205" and if it exists print the remainder of the line.
Code the problem one small step at a time to help from getting overwhelmed with the assignment. First, write the program that just opens the file. Get that to compile and work correctly. Then add to it the code needed to read each line using fgets(). Once that works you can continue with the reset of the assignment.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2007
Posts: 61
Reputation:
Solved Threads: 0
•
•
•
•
In your example if you enter "205" you will get nothing because there are no lines that contain "205"But I understand what you mean anyway.
>>pls include the codes
Please first post your code to show us the effort you are making to solve the problem.
I would read the file one line at a time using fgets() function. Then you can use either strstr() to see if the line contains the search string, such as "205" and if it exists print the remainder of the line.
Code the problem one small step at a time to help from getting overwhelmed with the assignment. First, write the program that just opens the file. Get that to compile and work correctly. Then add to it the code needed to read each line using fgets(). Once that works you can continue with the reset of the assignment.

c Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <stdio.h> using namespace std; int main() { FILE *fp; char data[50], *sd, p[50]; cout<< "Pls enter the string"; cin>> p; fp=fopen("q.csv", "r"); if(fp==NULL) { perror("Problem encountered"); } else { fgets(data, 50, fp); sd=strstr(data,p); if(sd!=NULL) { puts("file found"); } else { puts("file not found"); } puts(data); } return 0; }
Last edited by WaltP; Mar 29th, 2007 at 2:15 pm. Reason: Add CODE tags -- explained on the background of the post text box -- and FORMAT your code
That's a pretty complex assignment for someone who has only been studying c language for three days. If you are learning on your own you should start at the beginning of the book you are reading (you ARE studying a book aren't you???) and not in the middle.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2007
Posts: 61
Reputation:
Solved Threads: 0
•
•
•
•
That's a pretty complex assignment for someone who has only been studying c language for three days. If you are learning on your own you should start at the beginning of the book you are reading (you ARE studying a book aren't you???) and not in the middle.
How could I separate the strings separated by commas and consider it as one string?for example, i have a csv file:
from to name nick
0, 100, "help", "HP"
101, 201, "son", "SB"
202, 302, "dot", "DT"
if i enter a value the display wud be the nick. I must consider from and to.
for example
i entered 109, the program will then go to the second line since the value entered is in between the values 101 and 201. the output should be DT.
thanx in advance...
•
•
Join Date: Mar 2007
Posts: 61
Reputation:
Solved Threads: 0
How could I separate the strings separated by commas and consider it as one string?for example, i have a csv file:
from to name nick
0, 100, "help", "HP"
101, 201, "son", "SB"
202, 302, "dot", "DT"
if i enter a value the display wud be the nick. I must consider from and to.
for example
i entered 109, the program will then go to the second line since the value entered is in between the values 101 and 201. the output should be DT.
thanx in advance...
Look at the first character
If it's a digit, call a function that converts the next values up to the comma into a number. Return the next location (pointer or index) in the string just after the comma
If it's a ", call a function that moves everything up to the next " into a character buffer. Return the next location (pointer or index) in the string just after the comma
repeat the above two texts until you run out of characters for the line.
If it's a digit, call a function that converts the next values up to the comma into a number. Return the next location (pointer or index) in the string just after the comma
If it's a ", call a function that moves everything up to the next " into a character buffer. Return the next location (pointer or index) in the string just after the comma
repeat the above two texts until you run out of characters for the line.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Mar 2007
Posts: 61
Reputation:
Solved Threads: 0
•
•
•
•
Look at the first character
If it's a digit, call a function that converts the next values up to the comma into a number. Return the next location (pointer or index) in the string just after the comma
If it's a ", call a function that moves everything up to the next " into a character buffer. Return the next location (pointer or index) in the string just after the comma
repeat the above two texts until you run out of characters for the line.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Why NOT void main()
- Next Thread: Function prototype?? Help
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output parameter pointer problem program programming project python random read recursion reference rpg std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






