473,396 Members | 1,982 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.

Binary adress book-minor syntax -- mitola

17
#include <stdlib.h>
#include <stdio.h>
#include <string.h>


struct oseba
{
char ime[20];
char priimek[15];
char ulica[50];
char mesto[50];
char tel_st[10];
short ucni_uspeh;
}pod;

void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod.ime);
printf("Vnesi priimek: "); scanf("%s",pod.priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod.ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica,100,fd); //scanf("%s",pod.ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod.mesto);
printf("Vnesi tel st: "); scanf("%s",pod.tel_st);
fd=fopen("DIJAKI.BIN","a");
fwrite(&pod,sizeof(pod),1,fd);
fclose(fd);
}

void izpis(struct oseba pod,FILE *fd)
{
fd=fopen("DIJAKI.BIN","r");
fread(&pod,sizeof(pod),1,fd);
fclose(fd);
printf("%s %s\n", pod.ime, pod.priimek);
printf("Ucni uspeh: %d\n",pod.ucni_uspeh);
printf("Ulica: %s\n",pod.ulica);
printf("Mesto: %s\n",pod.mesto);
printf("Telefonska stevilka: %s\n",pod.tel_st);
}
int main(void)
{
FILE *fd;
int a;
int menu;
printf("------------------------------------------------------------------------------- \n");
printf(" IMENIK \n");
printf("------------------------------------------------------------------------------- \n");
printf("Vnesi izbiro:\n");
printf("1.)Vpis podatkov\n");
printf("2.)Izpis vseh podatkov\n");
printf("3.)Iskanje po imenu ali priimku\n");



scanf("%d",&menu);
switch(menu)
{
case 1: vnos(pod,fd);
break;
case 2: izpis(pod,fd);
break;
}

system("pause");
return 0;
}


heres the code :

void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod.ime);
printf("Vnesi priimek: "); scanf("%s",pod.priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod.ucni_uspeh);
printf("Vnesi ulico in st.: "); fgets(pod.ulica,100,fd);//here is the problem
//scanf("%s",pod.ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod.mesto);
printf("Vnesi tel st: "); scanf("%s",pod.tel_st);
fd=fopen("DIJAKI.BIN","a");
fwrite(&pod,sizeof(pod),1,fd);
fclose(fd);
}

well i have problem when trying to scan a string longer then one word for example: railroad 25
with normal scan i can rea only first word and i dont know how to correct this mistake so im asking for help.
Nov 20 '07 #1
3 1694
Use
Expand|Select|Wrap|Line Numbers
  1. gets();
  2.  
or

Expand|Select|Wrap|Line Numbers
  1. scanf("%[^\n]s",s);
  2.  
Nov 20 '07 #2
mitola
17
void vnos(struct oseba pod,FILE *fd)
{
printf("Vnesi ime: "); scanf("%s",pod.ime);
printf("Vnesi priimek: "); scanf("%s",pod.priimek);
printf("Vnesi ucni uspeh: "); scanf("%d",&pod.ucni_uspeh);
printf("Vnesi ulico in st: ");scanf("%[^\n]s",pod.ulica);
printf("Vnesi ime mesta: "); scanf("%s",pod.mesto);
printf("Vnesi tel st: "); scanf("%s",pod.tel_st);
fd=fopen("DIJAKI.BIN","a");
fwrite(&pod,sizeof(pod),1,fd);
fclose(fd);
}

i tryed that what you said and it dont wrote any syntax but just automaticly skips the : scanf("%[^\n]s",pod.ulica);

so how can i fix that i'll be able to actually wrote an ino there
Nov 21 '07 #3
use fflush(stdin)

Expand|Select|Wrap|Line Numbers
  1. void vnos(struct oseba pod,FILE *fd)
  2. {
  3.     printf("Vnesi ime: ");            scanf("%s",pod.ime);
  4.                 fflush(stdin);
  5.     printf("Vnesi priimek: ");        scanf("%s",pod.priimek);
  6.                 fflush(stdin);
  7.     printf("Vnesi ucni uspeh: ");    scanf("%d",&pod.ucni_uspeh);
  8.                 fflush(stdin);
  9.     printf("Vnesi ulico in st: ");scanf("%[^\n]s",pod.ulica);
  10.                 fflush(stdin);
  11.     printf("Vnesi ime mesta: ");    scanf("%s",pod.mesto);
  12.                 fflush(stdin);
  13.     printf("Vnesi tel st: ");        scanf("%s",pod.tel_st);
  14.                 fflush(stdin);
  15.     fd=fopen("DIJAKI.BIN","a");
  16.     fwrite(&pod,sizeof(pod),1,fd);
  17.     fclose(fd);
  18. }
  19.  
Nov 21 '07 #4

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

Similar topics

103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
0
by: Jarod_24 | last post by:
I got a function that return the url of a image, the problem is that the image control on the .aspx page automaticaly adds the adress of itself to the adress Example: The page...
3
by: Jarod_24 | last post by:
I got a function that return the url of a image, the problem is that the image control on the .aspx page automaticaly adds the adress of itself to the adress Example: The page...
6
by: LaVic | last post by:
Hello Everyone, I am trying to add two binary numbers in the form of two arrays. The code that i have been using compiles, but it does not give me the results i would expect. The problem that i...
0
by: Kai Mayfarth | last post by:
Hello Ist there a way to search a Adressbook over Python for a special contact. I know how i read and write a contact, but know i have to search over Python for some contacts, because the adress...
12
by: Registered User | last post by:
I've read in a book: <quote> With a binary-mode stream, you can't detect the end-of-file by looking for EOF, because a byte of data from a binary stream could have that value, which would...
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
3
Sagittarius
by: Sagittarius | last post by:
Hi there. I have a problem concerning an UDP socket in C++ (Winsock). The next paragraphs is merely to explain the system I am working on. If U want to skip it, I have marked the question in...
1
Mague
by: Mague | last post by:
Hey, There is a tutorial for Visual basics to make a adress book with SQL. I have followed the tutorial completly but it doesnt work. Its pritty simple to create. All you do is make a new data...
3
by: FARAECHILIBRU | last post by:
i'm building a binary tree the problem is when i'm reading from e text file .First i'm sending to tree builder function a empty node and e new node the function return me firt node of a tree, but...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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.