473,800 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help with this C code on files.

1 New Member
Expand|Select|Wrap|Line Numbers
  1. struct lib
  2. {
  3. char *name,*author,*publish;
  4. int price;
  5. int no;
  6. }u[50];
  7.  
  8. FILE *fp;
  9.  
  10. void fin()  //Inputs data to a file
  11. {  int i;
  12. fp=fopen("abc.txt","w");
  13.  
  14. for(i=1;i<=n;i++)
  15. {
  16.  
  17. fprintf(fp,"%s",&u[i].name);
  18.  
  19. putc('\t',fp);
  20. fprintf(fp,"%s",&u[i].author);
  21.  
  22. putc('\t',fp);
  23. fprintf(fp,"%s",&u[i].publish);
  24.  
  25. putc('\t',fp);
  26. fprintf(fp,"%d",u[i].price);
  27. putc('\t',fp);
  28. fprintf(fp,"%d",u[i].no);
  29. putc('\n',fp);
  30.  
  31. }
  32.  
  33. fclose(fp);
  34.  
  35. }
  36.  
  37.  
  38.  
  39. void fout() // Reads data from the file 
  40. {
  41. int i,x,j=0;
  42. char c,d[50];
  43. d[0]='\0';
  44. fp=fopen("abc.txt","r");
  45. for(i=1;i<=n;i++)
  46. {
  47. fscanf(fp,"%s",u[i].name);
  48. while((c=getc(fp))!='\t') ;
  49.  
  50. fscanf(fp,"%s",u[i].author);
  51. while((c=getc(fp))!='\t') ;
  52.  
  53. fscanf(fp,"%s",u[i].publish);
  54. while((c=getc(fp))!='\t') ;
  55.  
  56. fscanf(fp,"%d",&u[i].price);
  57. while((c=getc(fp))!='\t') ;
  58.  
  59. fscanf(fp,"%d",&u[i].no);
  60. while((c=getc(fp))!='\n') ;
  61.  
  62. }
  63. fclose(fp);
  64.  
  65. }


The strings read from the file are not stored in the structure. If I try to display the strings they appear as <null> . The numbers are input without any problem.
Please help as soon as possible.
Mar 18 '11 #1
1 1337
horace1
1,510 Recognized Expert Top Contributor
the following are pointers
Expand|Select|Wrap|Line Numbers
  1. char *name,*author,*publish;
  2.  
but what do they point too?
should they be arrays?
Expand|Select|Wrap|Line Numbers
  1. char name[20],author[20],publish[20];
  2.  
Mar 20 '11 #2

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

Similar topics

5
1646
by: Tom Willis | last post by:
How are the expert pythoneers dealing with config files? Is there anything similair to .net's config files or java's .properties? A quick search on google didn't return anything that looked useful, and I almost would expect to see some module that would be for dealing with config information. I can think of at least one way to do it, but I'm sure there are shortcomings I can't see yet, and I'd rather use something someone
1
1318
by: ghause | last post by:
I'm using a crypto stream to encrypt/decrypt files. It works fine with simple files like .txt but butchers pdfs and xls. Is there a solid way to encrypt/decrypt files that are more complex than plain text? Thanks
4
1544
by: serge | last post by:
I am thinking about replacing the INSERT data script files that I have with XML files. This way I can open the XML file using an XML Editor and see the values in a GRID and make changes easier. Do you see any problem with this approach? I managed to put together some code that is exporting a SQL table with its data to an XML file and also a code that reads the XML file's data and inserts it into a table.
0
1368
by: Lev | last post by:
Hi all, Anybody know how to send email message with attached files via WebDAV for Exchange (MS Exchange 2003 Server). Please, please, please! Need help! ASAP!!!! Tnx, Lev
4
3696
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the following code that compiles OK. It runs and shows the requested output. However, after execution, it pops one of those windows to send error reports online to the porgram creator. I have managed to find where the error is but can't see what's wrong....
6
2201
by: Peter Row | last post by:
Hi, Can someone give me a set of steps for an ASP.NET project (well actually its just a VB.NET class DLL that implements HttpHandler) that will work when moved to another developers machine? Here are some specifics: 1) The code, project/solution files are in MS Visual Source Safe
5
7086
by: Roshawn Dawson | last post by:
Hi, Has anybody created an entire asp.net app using only ashx files? I know that they are simply handlers used by the asp.net worker process. I hear that they are in some respects better than using aspx files because they don't have to be compiled and don't need any page processing. As an experiment, I'm creating an affiliate site that will use ashx files mainly. During testing I haven't noticed anything different other than it seems...
8
2322
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move thoe files to a specified directory. But couple of attempts did not work as desired this is one of them. Could someone help fix it or maybe give a better example.
0
1061
by: Alexnb | last post by:
Okay, so what I want my program to do it open a file, a music file in specific, and for this we will say it is an .mp3. Well, I am using the system() command from the os class. The problem I am running into is that when I send the path of the file to the system() command, which for those of you who don't know the system command is the equivalent of typing one command into command prompt or terminal depending on your system. But let's say...
34
5375
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.