Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
void main( )
{
  FILE * fp;
  char name[300],city[300],dept[300];
 /* fp=fopen("sampledata.ods", "r");*/
  if(!fp) {
   printf("File to open!\n");
   exit(1);
  }

  fscanf(fp,"%s%s%s",&name,&city,&dept);
  fp=fopen("sampledata.ods","r");
  fclose(fp);
  fprintf(stdout,"First Line is %s%s%s\n", name, city, dept);
  return 0;
}
Posted
Updated 7-Oct-14 21:32pm
v2
Comments
venkat28vk 8-Oct-14 5:58am    
Can I have the syntax to open the text(.odt file in ubuntu)

1 solution

You cannot read in a meaningful way .ods files that way (they are zipped XML files, as far as I know).
Anyway in the posted code, you are using fscanf before even opening the file.
 
Share this answer
 
Comments
enhzflep 8-Oct-14 4:17am    
+5"in the posted code, you are using fscanf before even opening the file."
o_O - oops!
CPallini 8-Oct-14 4:39am    
Thank you.
venkat28vk 8-Oct-14 5:46am    
how to open a text file(ubuntu it is .odt) could you specify me the syntax
enhzflep 8-Oct-14 5:56am    
Same as you open a text file anywhere. FILE *fp = fopen(fileName, mode); See here: fopen reference

But that still may not help you. Remember, ODT files (Open Document Text) may be zipped files. The basic content is text, which may be stored as text, or as a compressed (zipped) version of the text.

Why ODT file can not be opened by zip but can be opened by Open Office?
CPallini 8-Oct-14 6:03am    
.odt is actually an OpenOffice file. As far as I know, you have to open it in binary mode, unzip it, and then parse the XML content.
If yoou actually need a plain text file then don't use OpenOffice (or, on saving, choose .txt file format, if it allows you), use instead a text editor, like, for instance vi (or gedit).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900