#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.
3 1694
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
use fflush(stdin) -
void vnos(struct oseba pod,FILE *fd)
-
{
-
printf("Vnesi ime: "); scanf("%s",pod.ime);
-
fflush(stdin);
-
printf("Vnesi priimek: "); scanf("%s",pod.priimek);
-
fflush(stdin);
-
printf("Vnesi ucni uspeh: "); scanf("%d",&pod.ucni_uspeh);
-
fflush(stdin);
-
printf("Vnesi ulico in st: ");scanf("%[^\n]s",pod.ulica);
-
fflush(stdin);
-
printf("Vnesi ime mesta: "); scanf("%s",pod.mesto);
-
fflush(stdin);
-
printf("Vnesi tel st: "); scanf("%s",pod.tel_st);
-
fflush(stdin);
-
fd=fopen("DIJAKI.BIN","a");
-
fwrite(&pod,sizeof(pod),1,fd);
-
fclose(fd);
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |