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

Hi, I do not think this is a problem as such but an interesting behaviour to watch. I have little piece of C (to do with trying later Unicode, Polish characters and text files). I was trying to find a position of a Polish character in the alphabet string. Had some problems so I devised this simple temp. count display. See the comment line 35 starting: // observe the lines below. I have there simple 3xprintf() to print two lines being like a ruler and the alphabet string under: 000000000111 and so on up to 7 123456789012 and so on …

Member Avatar
Member Avatar
+0 forum 2

hello, I created a awk program to work witha data file to output a table and subtotal the rows and total up the collums and average I got it to work but when i added a presentation header before my totals go away. working code so far ------ can be viewed at http://cwl-host.com/linux/wtest and when i added the presentation headder my totals went away http://cwl-host.com/linux/test im using awk -f wtest datafile.dat

Member Avatar
Member Avatar
+0 forum 1

Hey guys, I'm working on a tip calculator as an excercise from the book I'm using to learn Java, and I've run in to a bit of a problem. When I run this code: import java.util.Scanner; public class TipCalculator { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print ("Enter the subtotal of your ticket:"); double subtotal = input.nextDouble(); System.out.print ("Enter the percentage you would like to tip:"); double tip = input.nextDouble(); double tipAmount = (subtotal * tip) / 100.0; double total = (tipAmount + subtotal); System.out.printf("The tip amount is $" + "%5.2f", tipAmount + "\n" + …

Member Avatar
Member Avatar
+0 forum 2

Hello, the output of this code is 'ef' but if we add up a "newline" print after this print then the output becomes 'efd'. Then why in earlier scenerio the 'd' was not getting printed ? Thanks in advance. #include<stdio.h> int main() { printf("\nab\bcd\ref"); }

Member Avatar
Member Avatar
+0 forum 9

Hey Guys, I'm want to output a calculation to a JLabel. Example: double num1 = 14; double num2 = 3; double ans; ans = num1/num2; JLabel jl = new JLabel(); add(jl); jl.setText("The Answer is: " + ans); Currently the answer for this will be 4.666666667. Now if this was a System.out statement I could have just done: `System.out.printf("The answer is: %.2f", ans);`. However, I can't. So what can I do to make the number diplayed in the JLabel look like 4.66. Thank-you

Member Avatar
Member Avatar
+0 forum 3

want to change all printf to cout with keeping the same output #include <iostream> using namespace std;Heading Here void main() { unsigned int a,b,c; char*format1 , *format2; format1 = "%04x%s%04x=%04x \n"; format2 = "%c%04x=%04x \n"; a = 0x0ff0; b = 0xf00; c=a>>4; printf (format1,a,">>",4,c); c=a&b; printf (format1,a,"&",b,c); c=a|b; printf (format1,a,"|",b,c); c=a^b; printf (format1,a,"^",b,c); c=~a; printf (format1,a,"~",b,c); system("Pause"); }

Member Avatar
Member Avatar
+0 forum 1

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

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

I am supposed to write a method to display a pattern as follows: ________1 _______21 ______321 _____4321 ____54321 ___654321 __7654321 _87654321 987654321 (underscores are simply placeholders to show alignment on my post they are not actually part of the printout) My program works and prints the aforementioned code correctly, however it does not right aligh to match up the "1"'s I know that I have to use a printf but im not quite sure what specifiers I need any help would be greatly appreciated, this is what I have so far: [ICODE]public class displayPattern { public static void main(String[] args) …

Member Avatar
Member Avatar
+0 forum 3

Hey guys i need to color code [CODE] printf("hello World");//how do i change this to green printf("How are you");//How do i change this to yellow or something [/CODE] How do i change the color of the text inside the printf

Member Avatar
Member Avatar
+0 forum 2

[CODE]void alternate(char wordWord[][MAX],char wordVar[],int word[],int i,int j, int k, int l) { char ang[4],si[3],ni[3],ay[3],sa[3],kay[4]; int X,Y,Z1,Z2; strcpy(ang,"ang"); strcpy(si,"si"); strcpy(ni,"ni"); strcpy(ay,"ay"); strcpy(sa,"sa"); strcpy(kay,"kay"); tokenize(wordWord,wordVar,word,i,j,k,l); if(wordWord[j][k] == ang[4] || wordWord[j][k] == si[3]) X = wordWord[j][k]; else if(wordWord[j][k] == ni[3]) Z1 = wordWord[j][k]; else if(wordWord[j][k] == ay[3]) Y= wordWord[j][k]; else if(wordWord[j][k] == sa[3] || wordWord[j][k] == kay[4]) Z2 = wordWord[j][k]; printf("%c %c %c %c %c %c %c \n",ang[4],si[3],ni[3],ay[3],sa[3],kay[4]); printf("%d %d %d %d\n",i,j,k,l); printf("Alternation 1: %c %c %c %c\n",Y,Z1,Z2,X); printf("Alternation 2: %c %c %c %C\n",Y,X,Z1,Z1); printf("Alternation 3: %c %c %c %c\n",Z2,Y,X,Z1); }[/CODE] is their something wrong with this? Every time I run it, it …

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

inr main () { int x=3,y=4,z=4; printf("%d",z>=y>=x), } the answer is zero ..how??

Member Avatar
Member Avatar
+0 forum 14

Hello, I have this code: [CODE] #include <iostream> #include <string> void main() { std::string a = "Sample"; printf("%s", a); std::cin.get(); } [/CODE] and it prints some I think random letters. Where i made mistake? And how should i change the code to write "Sample"? Thanks for answers and sorry for my english

Member Avatar
Member Avatar
+0 forum 8

I'm using the printf function to display some textual information. It is possible that the string may contain different symbols such as $#%^&* somewhere within the text. I know that to handle the % that I need to use a %% to make the string evaluate correctly. for example: [CODE] printf "strin%%g"; [/CODE] will display as strin%g <-- what I want My question is are there any other symbols that will give me issue using printf like % does? and if so, how do I handle them? Thanks so much!

Member Avatar
Member Avatar
+0 forum 3

Well... im making some kind of graphic engine for console in [B]c++[/B], ASCII based, just for exercise... anyways, i was wandering, can i print text [B]faster[/B]? Right now i'm printing the whole map of characters (pix[160][120]) in a [B]single line[/B], so it is fast, however i need it faster cause the screen is [B]flickering[/B] and it is realy annoying.. help please? im kind of newbie to console input output streaming..

Member Avatar
Member Avatar
+0 forum 7

//////////////////////////////////////////////////////////////////////////////////////// // In this little project I am trying to learn to get and manipulate data from // a file input using fstream strings I also wanted to use the formating available // with the printf and related string handling methods. I have a question in regards // to the two usages that I have shown in order to get char * from std::string. // // Is there a differance between the two things I have done? // Is one safer than the other because of allocatin for size? // Does it matter? // // Does anyone have any comments …

Member Avatar
Member Avatar
+0 forum 2

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

can u help me convert the cout to printf..i dont have a clue how.. tnx [CODE]#include<iostream.h> #include<string.h> #include<conio.h> int findSimilar(char[],char[]); void checkValue(int,int); int main(){ char boy[50]; char girl[50]; int similarInBoy=0; int similarInGirl=0; int total; clrscr(); cout<<"Enter Boy's Name: "; cin.getline(boy,50); cout<<"Enter Girl's Name: "; cin.getline(girl,50); similarInBoy=findSimilar(boy,girl); similarInGirl=findSimilar(girl,boy); total=similarInGirl+similarInBoy; cout<<"Boy: "<<similarInBoy<<","; checkValue(similarInBoy,1); cout<<"\n"; cout<<"Girl: "<<similarInGirl<<","; checkValue(similarInGirl,2); cout<<"\n"; cout<<"Total: "<<total<<","; checkValue(total,3); cout<<"\n"; getch(); return 0; } void checkValue(int similar,int gender){ if(gender==1){ if(similar>6) similar%=6; switch(similar){ case 1: cout<<"Friend"; break; case 2: cout<<"Love"; break; case 3: cout<<"Affair"; break; case 4: cout<<"Married"; break; case 5: cout<<"Enemy"; break; case 6: cout<<"Sweetheart"; break; } } else if(gender==2){ …

Member Avatar
Member Avatar
+0 forum 6

i found a very simple program that is very simple but have a great logic. [CODE] #include<stdio.h> #include<conio.h> void main() { int B=1; printf("%d\n%d\n%d",b=15,b>9,b<9); getch(); } [/CODE] this seems very simple to me but the output is very strange to me OUTPUT:- 15 0 1 I tried very much to understand this but i can't.. So please help me in understanding it...

Member Avatar
Member Avatar
+0 forum 7

hello, can someone explain me how this printf inside the function works? [CODE] #include<stdio.h> #define SIZE 10 void function(int [],int); int main() { int a[SIZE]={32,27,64,18,95,14,90,70,60,37}; function(a,SIZE); return 0; } void function(int b[],int size) { if(size>0){ function(&b[1],size-1); printf("%d ",b[0]); } } [/CODE]

Member Avatar
Member Avatar
+0 forum 8

hello everyone umm I'm having trouble in printing a structure in c... is a program to calculate benefits of employees in a company when they are fired.. getting trouble when printing the hired date of an employee here its the code [CODE]#include <stdio.h> #include <conio.h> #include <stdlib.h> void menu(); struct employee{ char company[70]; char name[50]; char hired_date[10]; char fired_date[10]; double salary[5]; }empl; int main() { menu(); gotoxy(31,4); gets(empl.company); gotoxy(31,5); gets(empl.name); gotoxy(31,6); scanf("%s", empl.hired_date); gotoxy(66,6); scanf("%s", empl.fired_date); gotoxy(20,19);printf("%s", empl.company); gotoxy(20,20);printf("%s", empl.name); gotoxy(20,21);printf("%s", empl.hired_date); //PROBLEM HERE!! gotoxy(20,22);printf("%s", empl.fired_date); getch(); gotoxy(45,24);system("pause"); return 0; void menu() { cuadrado(75,6,2,2); gotoxy(5,4); printf("Company Name.......:"); gotoxy(5,5); printf("Employee Name...........:"); …

Member Avatar
Member Avatar
+0 forum 2

Hi! I've recently converted some C code to a bit more native C++. This included changing printf() statements to std::cout statements. However, some printf()'s are rather lengthy and annoyingly long (and human-error-prone) to write in std::cout. Example (and this one is a short one): C-style: [CODE]printf("ERROR %d: %s: %s\n", event, origin ? origin : "?", fulltext.c_str());[/CODE] C++-style: [CODE]std::cout << "ERROR " << event << ": " << origin ? origin : "?" << ": " << fulltext << "\n";[/CODE] I personally find the first way much more clear and easier to write. What is the recommended way to do this …

Member Avatar
Member Avatar
+0 forum 4

The following lines of code output "FFFFFFFF" #include <stdio.h> int main(void) { int i; i=-1; printf("\n%X\n",i); return 0; } This is the 32-bit representation of -1 in Hex. I'm trying to get it to output fewer bits: e.g. 24-bit: FFFFFF In fact, the output I want needs to be 6 digits in all cases. So, if I replaced i=-1 with i=1 I need the output to be 000001. I can do this by padding with 0's (i.e., use printf("\n%06X\n",i);) but the negative case still outputs FFFFFFFF. I vaguely understand why this is happening, but not sure the easiest way to …

Member Avatar
Member Avatar
+0 forum 7

I came across these to statements and i am not sure how they are parsed and the output given is produced... [CODE] printf("%d",printf("%d %d",5,5)&printf("%d %d",7,7)); [/CODE] o/p : 5 5 7 7 3 [CODE] printf(" %d %d",printf("%d %d",7,7),printf("%d %d",5,5)); [/CODE] o/p : 5 5 7 7 3 3 Could some one explain where the two 3 's r obtained from. They r not random , i think its got something to do with the length of the output but not sure.

Member Avatar
Member Avatar
+0 forum 1

Write a program that displays the table of Fahrenheit - Celsius temperatures. Below is my code, the problem with it is that the celsius column is all zeros,please correct my mistake, thank you: [CODE]#include "stdafx.h" #include "genlib.h" #include "simpio.h" #include "math.h" int _tmain(int argc, _TCHAR* argv[]) { int i; double c; printf("Fahrenheit Celsius\n"); for (i=0;i<=0;i+=20) { c=(5/9)*(i-32); printf("%d %f\n",i,c); } for (i=20;i<=80;i+=20) { c=(5/9)*(i-32); printf("%d %f\n",i,c); } for (i=100;i<=200;i+=20) { c=(5/9)*(i-32); printf("%d %f\n",i,c); } }[/CODE]------------------------------------------------------------------------------------- I tried using %g instead of %f, but it's still all zeros. ------------------------------------------------------------------------------------- The output should appear as follows: [CODE]Fahrenheit Celsius 0 -17.8 20 -6.7 …

Member Avatar
Member Avatar
+0 forum 3

I need the coding for the following question in C: Read and print all the consonants from a file (no duplicates). Assume the file is a .txt file. The consonants are then to be sorted in alphabetical order.

Member Avatar
Member Avatar
-6 forum 2

Dear all, I am working on the code below: [CODE] int cookTime(int time) { int second, minute; for (minute = time; minute > -1; minute--) { for (second = 59; second > -1; second--) { sleep(1); printf ("%i", minute); printf (" : %i\n", second); } } } [/CODE] Now this works as I want it. So it produces an output which goes like this: 5 : 59 5 : 58 5 : 57 .... etc. until it reaches 0. Now I would like to modify the printf line so that the numbers are constantly refreshing on the same line. I …

Member Avatar
Member Avatar
+0 forum 8

Hi all, I hope you are well. I am trying to compile a java file using terminal in Ubuntu, but I am getting the following error message: [QUOTE]1. ERROR in StringComparisons.java (at line 20) System.out.printf("String a = %s String b = %s \n", a,b); [/QUOTE] As you can see, I am passing three String arguments to the printf method, which, as far as I can tell from the API is perfectly legal as this would correspond to the object varargs printf method. [QUOTE]printf public PrintStream printf(String format, Object... args) A convenience method to write a formatted string to this output …

Member Avatar
Member Avatar
+0 forum 5

The End.