Currently doing C programming homework, I want to update the value in the file. But now I'm having a problem updating it. The problem I faced now was the codes below update the values but in the form of new lines. Instead of replace the original lines. What's wrong with my codes ? FILE* phoneFile; int position_in_file,newStock; printf("Enter new stock: "); scanf("%d",&newStock); position_in_file = ftell(phoneFile); fseek(phoneFile,position_in_file,SEEK_SET); fprintf(phoneFile,"%s %s %d %d %d\n",mobile[i].mCode,mobile[i].mName, &mobile[i].mCost,&mobile[i].mPrice,newStock);

Member Avatar
Member Avatar
+0 forum 2

when converting iget erros especially in the cin parts because they are automatically passed by something #include<iostream> #include<conio.h> #include<math.h> using namespace std; int p=1; class Bank { public: char name[50],address[90],type; double ein_betrag, aus_betrag; double balance; int costumernr, accountnr, birth, tel; public: void newcostumer(); void newaccount(); void costumerdel(); void accountdel(); void deposit(); void withdraw(); void accountinfo(); }; void Bank::newcostumer() { cout<<"\n Enter your name : " << endl; cin>>name; cout << " Enter your address: " << endl; cin >>address; cout << " your tel nr please: " << endl; cin >>tel; cout << " Enter your gebdatum: " << endl; …

Member Avatar
Member Avatar
+0 forum 2

Hi, i have this project where the size, 2d array of size n is scanned from a file; asks for the vertex pairs from the command prompt until the user decides to stop inputting them. There is something wrong with my code because it skips the scanning of int variables from and to. Please help me and tell if you spot the problem. Thanks :) int repeat() { char rep; printf("\n\n Proceed to Next Matrix? Y / N: "); rep = getchar(); scanf("%c", &rep); if(rep == 'Y') return 1; else if(rep == 'N') return 0; } int operate() { char …

Member Avatar
Member Avatar
+0 forum 4

** # import a data table with space? # ** Good day! I need to read in all the data in a file within column two and export it in a file. The issue is the data is not standard and has blank fields from time to time. It also has issues like "N/A" that i would want to delete. So i just need some direction. C... is a fickle beast ya know. The reason being i need to inport a printer file and process the information to export only the document numbers. for example... 10 HIHM07A1 10 Hj NDt …

Member Avatar
Member Avatar
+0 forum 13

This is an example of a singly linked list allowing you to enter a number of names and associated ages. The twist is that the names are inserted into the list in ascending order. When the list is displayed, it is already sorted by name. Note: This is not an exercise in safe data input. While precautions have been taken, any fool can stress the language easily.

Member Avatar
Member Avatar
+1 forum 7

Here is what I'm trying to do: * Take input with scanf() * Pass input to function * Beep frequency associated with input I have notes defined, e.g `const in C5 = 523.25;` I want the user to be able to input "C5", and have the computer beep at a frequency of 523.25. When I run my code, I get the same sound no matter what I input, even if it is just random letters. I am fairly new to C, but I think what is happening is that the function is trying to beep at the frequency of the …

Member Avatar
Member Avatar
+0 forum 5

Hi, I am trying to write a program which read a certain input in a particular format and then gives an ouput. I wrote a code to read the file. Input is something like this. X 20 60 80 90 X 78 98 97 96 X 34 35 43 23 Y 76 87 34 Y 65 76 72 Z 13 70 39 So my reading function read the input and then it counts the number lines with X and Y. Now, when I wrote two different funcions to read X and Y lines. When I am finished reading the X …

Member Avatar
Member Avatar
+0 forum 4

Hi I have the following code which is giving an error while trying to use scanf with it. Please help resolve uint16_t x[3]={1,2,3}; uint16_t y; printf(" %"PRIu16",y); (works) printf("Enter a value for y: "); scanf("%"PRIu16, &y); warning: format '%u' expects argument of type 'unsigned int *', but argument 2 has type 'uint16_t *' [-Wformat]

Member Avatar
Member Avatar
+0 forum 3

I need help with this http://codepad.org/FNUci22s I am posting the ling of code pad because it has a way to execute it, so long story short. I use two different functions seno, sen (both for sin). When using the printf and adressing both to compare results I get from the seno function the correct result(sin(45)=0.70710) but the moment I remove the other function from the printf i get "nan". Funcitons dont depend from each other.

Member Avatar
Member Avatar
+0 forum 2

After much searching I cannot find a particular way to get a datafile into my structure. I understand how to create and manipulate the structure. C does not play nicely with strings is another thing I have noticed. I have tried many examples of how to do this but none of them work. [CODE] #include <stdio.h> #include <string.h> int main() { struct citydata { char city[20]; int temp; }; struct citydata values[15]; //These will be used later struct citydata Avg; struct citydata high; struct citydata low; FILE * inp; int reccount = 0; int x = 0; char s; int …

Member Avatar
Member Avatar
+0 forum 6

# code to convert any base input to any base output (base limited upto hexadecimal) # ## scanf() works , but gets() stops working from 2nd iteration ## *i apolozise beforehand for the length of this post, i hope there will be someone who'll bear with me :(* **here is my code, the one with scanf(). this one has no problems and works just fine. :)** #include<stdio.h> #include<conio.h> #include<stdlib.h> int entry();// gets any base input and converts it to decimal int main(void){ int ip_num,ip_base,op_num,op_base,i=0,cont_flag,acc[20]; char base_digits[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; do{ ip_num=entry(); printf("choose the base to convert to:"); scanf("%d",& op_base); puts("\nin main()\n\nexecuting …

Member Avatar
Member Avatar
+0 forum 11

anybody help me "how to write our own (by user) scanf function so that it will works exactly as scanf function defined in liberary, what will be its declaration and definition ".

Member Avatar
Member Avatar
+0 forum 1

Hello all! I have used this forum many times in the past to solve a variety of programming related problems, but am truly stumped on a segfault within a binary search tree. I have isolated the segfault to a fscanf statement that look legitamate to me. The following code blocks are the function that contains the fscanf statement: int fscan_unit(FILE *filep, object_t *object){ int status; /************************** SEGFAULT **************************/ status = fscanf(filep, "%d%d%d%s", &object->id, &object->section, &object->credits, object->course ); /************************** SEGFAULT **************************/ if(status == 4){ status = 1; } else if(status != EOF){ status = 0; } return status; } and the …

Member Avatar
Member Avatar
+0 forum 2

Hi all! I was experimenting a little with scanf. I am posting the code and the outputs I am having prolems understanding: #include <stdio.h> int main() { char a,b,c; int d,e; scanf("%c%c",&a,&b);//-------------------(1) printf("%c %c\n\n",a,b); scanf("%d%d",&d,&e);//-------------------(2) printf("%d %d\n\n",d,e); scanf("%c abc",&a);//--------------------(3) printf("%c\n\n",a); scanf("%c abcdefgh",&a);//---------------(4) printf("%c\n\n",a); getch(); return 0; } In (1): Doesnt work. Scanf only takes one input. For (2), the same thing works. Why is it that it works for integers but not characters? In (3): Lets say I input 'm'. The subsequent printf prints nothing. After that, for scanf in (4) if I input 'k', then the subsequent printf prints …

Member Avatar
Member Avatar
+0 forum 9

My code is this atm: #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int a,b,c; int swap; printf("Enter 3 Numbers (# # #):"); scanf("%d %d %d", &a,&b,&c); //does all its computing, to see which one is biggest. return EXIT_SUCCESS; } The result when i run it in eclipse is that, I have to put in 3 numbers first, THEN it says "Enter 3 Numbers (# # #):" (So it stays blank at start of program) I remember I had this problem a long time ago but I have switched back to eclipse now and somehow this happens. :/ Thanks …

Member Avatar
Member Avatar
+0 forum 6

Im trying to write a program that will scan both characters and numbers from a user then put the number into an array or call another function based on the user input. For example the user will type 'Insert 3' and this will call the function to put 3 into an array. my problem is im not sure how to read the letters as letters and evaluate them so i know which function to call and at the same time read the number as a number and put it into an array. Im not sure how clearly im explaining things …

Member Avatar
Member Avatar
+0 forum 5

Hello! I have a problem. I can't use scanf() to set a value of the second member of the person struct. Why? I get an error that tells me "bad access". [CODE]int main(int argc, const char * argv[]) { struct Adress{ char *street; char *postal; int zip; }; struct Person{ char *firstName; char *lastName; struct Adress home; }; struct Person newPerson; printf("Enter your first name and last name: \n"); scanf("%s %s", newPerson.firstName, newPerson.lastName); printf("Hello %s %s! \n", newPerson.firstName, newPerson.lastName); }[/CODE]

Member Avatar
Member Avatar
+0 forum 4

This is my first post on daniweb :) and i am a beginner in C programming and i don't know so good english :) sorry! This is my program My problem consist of I run the program and i can't get to the [B]scanf("%c",&q);[/B] [I]/* Row 21 after printf. */[/I], the program considered that i have already asigned a char value to the variable [B]q[/B] Where i'm wrong! thanks in advance for understanding! :thx: ps: there are spoilers on topic, can i use them ?! this program i finished in pascal and manualy converted to C [CODE=C] #include <stdio.h> #include …

Member Avatar
Member Avatar
+0 forum 3

Hi all, I am just going through C++ basics now and I read that enum types cannot be input directly with cout and cin and such.And also that type coercion from int to enum is not allowed.But when i do this, [CODE] enum SumEnum{ENUM1,ENUM2,ENUM3} SumEnum VarEnum; scanf("%d",&VarEnum); printf("%d",VarEnum); [/CODE] It happens perfectly.printf is ok because enum to int coercion is allowed,but how come scanf works if int to enum is not allowed? Thanks in advance.

Member Avatar
Member Avatar
+0 forum 1

In a language named vJass I can do this: [CODE] function Initialization takes nothing returns nothing string array s call read(s[1]) call read(s[2]) call print(s[1] + " " + s[2]) endfunction[/CODE] It takes two strings from user and prints them. I am totally confused how I can do this in C...

Member Avatar
Member Avatar
+0 forum 13

I'm trying to read user input and store it as a string including the whitespace. I did a search for a solution and was pointed to fgets() or scanf(%[^\n], str). But both these solutions give me an error. This is what I have: [CODE] scanf("%d", &input); if (input == 1){ int pr; char na[MAX_CHARACTERS+1]; printf("\nEnter the name: "); scanf("%[^\t\n]", &na); while (strlen(na)>MAX_CHARACTERS){ printf("\nName is too long, enter new name: "); scanf("%[^\t\n]", &na); }// end na check printf("\nEnter priority: "); scanf("%d", &pr); while (pr>MAX_PRIORITY || pr <MIN_PRIORITY){ printf("\nBad priority, enter new priority (0-100): "); scanf("%d", &pr); }//end pr check[/CODE] It works …

Member Avatar
Member Avatar
+0 forum 6

I am trying to take a user input phone number and perform calculations on it as an integer of type long long. I've tried this but it only reads the first 3 numbers then when it reaches the hyphen it stops. [CODE=C] printf("Enter Number: \n"); //get input from user count = scanf ( "%[0-9]%n", hold, &len ); //check number of inputs and length of input number = atoll(hold);[/CODE] so if i get a number like 555-123-9876 it will convert it to 5551239876 but i also need to be able to read numbers put in as 5551239876 any help would be …

Member Avatar
Member Avatar
+0 forum 9

[code = c][/code] I am trying to write a program that takes a 10 digit phone number and inserts hyphens between the 3rd and 4th digit and the 6th and 7th digit eg. Enter phone number: 5553459875 Your number is 555-345-9876 I've decided that reading the number as an integer won't work and tried reading each as a char but then it still doesn't print how I want it to Any help would be appreciated Thanks

Member Avatar
Member Avatar
+0 forum 2

Hello I have been using c for dummies along with bloodshed software for a day or so and I tried putting this snippet of code in from the book and I got a syntax error:[CODE]#include <stdio.h> int main() { char name[20]; char color[20]; printf(“What is your name?”); scanf(“%s”,name); printf(“What is your favorite color?”); scanf(“%s”,color); printf(“%s’s favorite color is %s\n”,name,color); return(0); }[/CODE] I figured this book was up to date (2004) and up to this point the only error I got was from using () around 0 in return. But for some reason this won't compile. And I copied and pasted …

Member Avatar
Member Avatar
+0 forum 3

i need a command in c++ to scan the first keystroke the user enters ....(i.e) user doesnt have to press <enter> key...i need to scan as soon as he types....please help...thanks in advance....

Member Avatar
Member Avatar
+0 forum 4

Hi friends, well... i'm asking for another help from you guys.hope you will... My friend sent me a email asking why the following code doesn't work properly.I'm also couldn't understand what's happening..When this program run it supposed to prompt two times to enter values.but its actually prompt once. I tried to clean input buffer,but it seems like the same.please anyone can help.I'm sure you guys can..thank you in advanced. i'm running this on ubuntu. [ICODE] #include<stdio.h> #include<string.h> void main() { char check[5]; prter:intf("En- "); scanf("%s",check); printf("%s\n",check); printf("%.2s\n",check); printf("Re-Enter:- "); fflush(stdin); gets(check); printf("%s\n",check); }[/ICODE]

Member Avatar
Member Avatar
+0 forum 6

I have a unit conversion program that needs to take in a float and 2 strings from standard input. My previous solution was: [CODE] float orig_quant; char *orig_name = (char*) malloc(MAX_CHARS); char *new_name = (char*) malloc(MAX_CHARS); fscanf(stdin, "%f %s %s", &orig_quant, orig_name, new_name); [/CODE] However, this only works if the input looks like [B]2.54 centimeters inches[/B] A requirement for the project is that the input looks like this [B]2.54, centimeters, inches[/B] I tried to change my fscanf to something like fscanf(stdin, "%f, %s, %s"...) but that didn't work. What is the easiest way I can get rid of those commas …

Member Avatar
Member Avatar
+0 forum 5

I can't seem to pass a struct address to a function. My program "stops working" when it gets to the scanf statement of the getReady function. [CODE]/**************************************************** Author: ---------------------------------------------------------------------- Purpose: This code will explore passing a data structure address to a function. ****************************************************/ #include <stdio> #include <stdlib> //prototypes: struct things{ char knife; char pen; char wallet; char keys; }; int getReady(struct things *t,char x); void main() { char ready; char r; struct things *t; ready =getReady(t,r); if (ready == 'y') printf("\nLet's go!!!"); } int getReady(struct things *t,char x) { printf("\nHave you got your wallet? y/n: "); scanf("%c",t->wallet); printf("\nHave you got …

Member Avatar
Member Avatar
+0 forum 3

[CODE]main() { char name[10],s[12]; scanf("\"%[^\"]\"",s); }[/CODE] How this scanf will scan?

Member Avatar
Member Avatar
+0 forum 2

Hi, every one know that scanf statement should use "&" ambers ion symbol, but why it is not used while getting a string. eg: main() { int a; char str[10]; scanf("%d",[COLOR="Red"]&[/COLOR]a); scanf("%s",str); -->why "&" sybbol is not used in getting string? }

Member Avatar
Member Avatar
+0 forum 5

The End.