| | |
fgets/puts creates weird output
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Dear all,
I have a weird problem reading a file using fgets. The code below should read the first line of the file "F:\\filename.csv". It works for all sorts of files that I create myself, but it does NOT work for certain files that I download from the internet.
More precisely, I download a csv file from Google Insight (see http://www.google.com/insights/search/#q=London&cmpt=q), and when I try the code on the downloaded file, I don't get the first line but the string has the following value: "ÿþW", which displays as a little square, followed by a capital "W".
Any ideas what's going wrong?
This is the code that I'm using:
I appreciate any help!
Thanks a lot,
Anne
I have a weird problem reading a file using fgets. The code below should read the first line of the file "F:\\filename.csv". It works for all sorts of files that I create myself, but it does NOT work for certain files that I download from the internet.
More precisely, I download a csv file from Google Insight (see http://www.google.com/insights/search/#q=London&cmpt=q), and when I try the code on the downloaded file, I don't get the first line but the string has the following value: "ÿþW", which displays as a little square, followed by a capital "W".
Any ideas what's going wrong?
This is the code that I'm using:
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> int main () { FILE *in=fopen("F:\\filename.csv","r"); char mystring [100]; fgets (mystring , 100 , in); puts (mystring); fclose (in); return 0; }
I appreciate any help!
Thanks a lot,
Anne
Last edited by anne_1000; Jul 16th, 2009 at 5:56 am.
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Hi adatapost,
thanks again. I tried using wstring, but the following code does not even compile, and I can't quite figure out why.
Any ideas what's going wrong?
The first error message referes to line 16; it says
But this doesn't help me in any ways..
Sorry I might be being stupid but I have just started using C/C++.
Thanks,
Anne
thanks again. I tried using wstring, but the following code does not even compile, and I can't quite figure out why.
C Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream myfile("F:\\filename.txt"); wstring line; if (myfile.is_open()) { while (! myfile.eof() ) { getline(myfile,line); wcout << line << endl; } myfile.close(); } return 0; }
Any ideas what's going wrong?
The first error message referes to line 16; it says
•
•
•
•
error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files\microsoft visual studio 8\vc\include\string(528) : see declaration of 'std::getline'
Sorry I might be being stupid but I have just started using C/C++.
Thanks,
Anne
•
•
Join Date: Jul 2009
Posts: 4
Reputation:
Solved Threads: 0
Thanks a lot. I have been trying all sorts of code from the internet to convert unicode strings to ascii strings, but so far nothing works. Most of the stuff that I find online is pretty long, and impossible to understand for me as a beginner.
The following code should do it, but I get an error when compiling.
The error is
Could someone tell me what that means, or how I can find out myself what the error is?
Thanks,
Anne
The following code should do it, but I get an error when compiling.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> using namespace std; int main() { wchar_t WideStr[] = L"Unicode!"; char x[] = "longlongstring"; wcstombs(&x, WideStr, 1024); return 0; }
The error is
•
•
•
•
error C2664: 'wcstombs' : cannot convert parameter 1 from 'char (*__w64 )[15]' to 'char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>myCOnverter.cpp
Thanks,
Anne
if u can do some manual work then
1)Open your Unicode file with notepad and save as ANSI.
Then read that file it using C
or else
in DOS use
command:type filename > filename1
Then read the filename1 using C
-----------
If your want to develop a Unicode reading tool using C then
You can go by Ancient Dragon or adatapost.
Thanks,
DP
1)Open your Unicode file with notepad and save as ANSI.
Then read that file it using C
or else
in DOS use
command:type filename > filename1
Then read the filename1 using C
-----------
If your want to develop a Unicode reading tool using C then
You can go by Ancient Dragon or adatapost.
Thanks,
DP
![]() |
Similar Threads
- Weird output (PHP)
- weird output (Shell Scripting)
- Char array, getting weird output (C++)
- Is it possible to arange lines in a file alphabetically? (C)
- Multiple file creates (C)
- Playing with inputs (C++)
- don't understand (C++)
- Reversive Array/Integer (C)
Other Threads in the C Forum
- Previous Thread: Find array placement
- Next Thread: Airline Ticket Reservations System
Views: 530 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for C
* .net api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked reversing scheduling segmentationfault send single socketprogramming spoonfeeding standard strchr string student suggestions system test testautomation testing unix urboc user whythiscodecausesegmentationfault win32api windowsapi






