![]() |
| | #1 |
| Registered User Join Date: Dec 2008
Posts: 13
| I have a file stream called "src" and I am reading in lines from that file. The file contains information about sms messages. The very first line tells us, how many messages are stored in the file. Then, every message takes up two lines: the first line containing information about the date of reception and the sender, the second line containing the message itself, with a length of 100 chars at maximum. The file contains 30 messages, thus it is 60+1 lines long. My task is, to tell which message is the shortest, and which one is the longest. I have started with this code: Code: ...includes...
...var declarations...
char shortest_msg[100];
char longest_msg[100];
...some code...
...even more code...
for(i=0;i<=number_of_msg*2;i++){
fgets(current_line,100,src);
if(i==0)
continue;
else if(i/2==0){
}
else if(i/2==1){
if(strlen(shortest_msg)>strlen(current_line))
shortest_msg=current_line;
else if(strlen(longest_msg)<strlen(current_line))
shortest_msg=current_line;
}
}
Last edited by laczfinador; 05-06-2009 at 07:46 AM. |
| laczfinador is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| You cannot assign to arrays, so you should use say, strcpy() instead.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #3 |
| Registered User Join Date: May 2009
Posts: 4
| use memcpy() to copying current_line to shortest_msg, I think you unable to assign another address of pointer ( shortest_msg is address of shortest_msg[0] same as &shortest_msg[0]). |
| ReeV is offline | |
| | #4 |
| Registered User Join Date: Dec 2008
Posts: 13
| Greetings, and thanks fro the replies! The strcpy() function did the job well, and it seems easy to use even. Wish everything couls be solved so easily... |
| laczfinador is offline | |
![]() |
| Tags |
| array, arrays, fgets, invalid lvalue assignment |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Static Arrays, C++ uses an odd method of assigning values? | Norehsa | C++ Programming | 5 | 06-10-2007 05:54 AM |
| question about multidimensional arrays | richdb | C Programming | 22 | 02-26-2006 09:51 AM |
| Eliminating duplicate values from a 20x2 array | desipunjabi | C Programming | 2 | 10-29-2005 09:11 PM |
| Type and nontype parameters w/overloading | Mr_LJ | C++ Programming | 3 | 01-02-2004 01:01 AM |
| Inputted values into an array | Panther | C Programming | 6 | 04-11-2003 10:15 AM |