473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read a CSV File from a Flash drive (Using C++, Ubuntu 12.04)

I want to read a file from my flash drive called text.csv. However, I cannot even open the port where my flash drive is connected. This is the code that I am using, but I get error since the first part. When I run the program it says "fopen Error". I am using Ubuntu 12.04. Please help.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. #define SIZE 1
  5. #define NUMELEM 5
  6.  
  7. int main(void)
  8. {
  9.     FILE* fd = NULL;
  10.     char buff[100];
  11.     memset(buff,0,sizeof(buff));
  12.  
  13.     fd = fopen("/dev/sdc/test.csv","r");
  14.  
  15.     if(NULL == fd)
  16.     {
  17.         printf("\n fopen() Error!!!\n");
  18.         return 1;
  19.     }
  20.  
  21.     printf("\n File opened successfully through fopen()\n");
  22.  
  23.     if(SIZE*NUMELEM != fread(buff,SIZE,NUMELEM,fd))
  24.     {
  25.         printf("\n fread() failed\n");
  26.         return 1;
  27.     }
  28.  
  29.     printf("\n Some bytes successfully read through fread()\n");
  30.  
  31.     printf("\n The bytes read are [%s]\n",buff);
  32.  
  33.     if(0 != fseek(fd,11,SEEK_CUR))
  34.     {
  35.         printf("\n fseek() failed\n");
  36.         return 1;
  37.     }
  38.  
  39.     printf("\n fseek() successful\n");
  40.  
  41.     if(SIZE*NUMELEM != fwrite(buff,SIZE,strlen(buff),fd))
  42.     {
  43.         printf("\n fwrite() failed\n");
  44.         return 1;
  45.     }
  46.  
  47.     printf("\n fwrite() successful, data written to text file\n");
  48.  
  49.     fclose(fd);
  50.  
  51.     printf("\n File stream closed through fclose()\n");
  52.  
  53.     return 0;
  54. }
Mar 26 '13 #1
1 1700
Banfa
9,065 Expert Mod 8TB
Plug in your USB device and use ls in a command prompt to locate it. From memory (and because I can't be bothered to switch on my second computer) USB flash drives are not mounted on /dev but on /media
Mar 26 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: will.leighton | last post by:
I am working on concept where I want to deliver web-based content and functionality from a USB Flash drive for users who don't have access to the Internet. The functionality includes personaliztion...
2
by: createdbyx | last post by:
I am trying to make a file sync utillity to sync files between my laptop and my desktop pc. On my desktop machine (xp pro sp2) I have shared my "Visual Studio Projects" folder using windows simple...
5
by: Dustin Davis | last post by:
This might be a pipe dream, but here goes... I'm writing an application many users will be working on and saving files to USB flash drives. When they click the save button, I would like to have...
2
by: Joe Cool | last post by:
I know this is probably not the proper newsgroup to ask this question, but I do not know which one is. And most of you guys here know a lot about windows programming so I am taking a chance some...
3
by: ryancol | last post by:
I have a couple usb 2.0 flash drives. I use them on either windows 2000 or windows XP. When I copy (drag and drop) a file folder to them such as a file folder with like 10 or 20 pictures in it the...
0
Chrisjc
by: Chrisjc | last post by:
<Excerpted from this thread> All of these questions and answers are great. But it comes down to this I have seen this more than enough times to know better... From my experience at home and as...
3
kestrel
by: kestrel | last post by:
Hey, I have an 8 gb flash drive. ive been using it to transfer all of my music from one computer (linux) to another (windows xp, if it really matters). After all my transfers were completed, i stuck...
2
by: TheeStudent | last post by:
Can someone help me out on how to let a C Sharp program automatically scan a flash drive or CD as soon as it's entered in your PC? I have created a basic ATM program and what I intend to do basically...
0
by: bellavidae | last post by:
I plugged in my flash drive to my Toshiba laptop, OS Windows 7. When I tried to access the drive, I got a message saying I needed to format the flash drive before using it. If I format the drive,...
1
by: Agnija | last post by:
i have a 8GB usb flash device , and I have been using it without problems for several months. Now when I plug it in, the drive comes up in my computer as drive E as it usually does, . If I format it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.