C/C++ :: Using Write In A For Loop?

Sep 23, 2014

i am having some trouble with a piece of code im writing for class.

here is my code

for (j=7; j>=0; --j){
putchar((name[i] IF_STATEMENT);
write(1, " ", 1);

I am trying to use write to format my output so that it looks like this

0 0 0 0 0 0 0 0

The formatting works fine when i use printf("%s", " "); in place of write but for some reason when i use write the format comes out like this

00000000

I dont understand why this is happening. Does write always work outside of a for loop or something?

View 6 Replies


ADVERTISEMENT

C++ :: How To Write A Data Loop

Feb 14, 2013

I need to write a data input for one of my class assignment. Would this be considered a data loop?

while (cin >> number)

View 4 Replies View Related

C :: Switch Inside A While Loop - Write Min And Max To Get Negative Numbers

Nov 25, 2014

I got the while loop right... but how do i write the minimum and max to get negetive numbers like -88....

Code:
#include <stdio.h>#include <math.h>
#include <conio.h>
int gcd(int, int);
int main() {
int x, y, min, max, result, power, flag = 1;
char c;

[Code] ....

View 6 Replies View Related

C++ :: Write Interactive Text Based Menu Interface (using A Loop)

Sep 27, 2013

Write an interactive text based menu interface (using a loop) that will allow the user to

Enter a task or assignment Display all of the tasks that are in the file Find a task by Course Quit For each task, you need to keep track of:

Course Name that it is for (e.g., CS162)
Description of the assignment (e.g., Finish Lab 2)
Due date (e.g., 9/26/2009)

Allow the program to keep looping until user wants to quit. When the program starts, it should load the tasks from external file ("tasks.txt") into memory. When user enters the three items of a task, the program needs to read them in, save them in memory and eventually write them to the external data file ("tasks.txt"). The file format could look like: (The ';' is used as a delimiter or field seperator.)

Some Implementation Requirements:

Write at least four functions WITH arguments for this assignment. Use struct named Task to model task Use array of structs to model the collection of tasks. Hint: In this assignment, the description and course name may have multiple words in it. Therefore, you now SHOULD read using the 3 argument version of get. Watch out. When using the 3 argument version of get you need to make sure to remove the delimiter or newline. Therefore, anytime you read (even a confirmation message), make sure to eat the newline! Make sure to have a delimiter written between each item in the file – like a newline. This will be important when you read the information back from the file.

This is my code so far:

#include <iostream>
int main()
{
char cname[25],desc[20];

[Code]....

View 1 Replies View Related

C++ :: Write Data Into Files In A For Loop - Debug Assertion Failed?

Apr 14, 2012

In my program I open two files and write data into each, and close them. this is done in a while loop.

int main() {
while() {
myFile = fopen("file1.txt","w");
myFile2 = fopen("file2.txt","w");
// write data into files using fprintf() in a for loop
fclose(myFile);
fclose(myFile2);
}
}

However, after some iterations the fopen() for myFile2 fails.

Debug assertion failed!
Program....
File ......srcfprintf.c
Line 55

Expression (str != NULL)

I have not been ableto locate the bug in the code that is causing the failure.

View 7 Replies View Related

C++ :: Write A Loop Assigning Variable X To All Positions Of String Variable

Sep 8, 2013

I have to write a loop assigning a variable x to all positions of a string variable and I'm stuck. I don't have extensive experience with arrays and I'm also a bit confused about C-String. The problem is below.

"Given the following declaration and initialization of the string variable, write a loop to assign 'X' to all positions of this string variable, keeping the length the same.

char our_string[15] = "Hi there!";

(Please note this is a 'C-string', not C++ standard string.)"

View 5 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

#include <iostream>
using namespace std;
int main () {
int len;
int j;
int i;

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C :: How To Write COS / TAN / SIN

Jul 25, 2013

I know I need <math.h> and I know how to write tan(10) or whatever I need. However I need angles, like 100 / tan10 = 567.13. The 10 is degrees.

I am doing a fun project now that I feel more confident. However my textbook only shows me how to use the math library and only shows a few trig functions.

I am applying Trigonometric Functions to see if a car is speeding.

View 3 Replies View Related

C :: How To Get Program To Write Itself

Aug 27, 2013

For instance Code: int counter;
counter =0;
FILE *pfile;
pfile= fopen("g:myprog.txt" "w");
while (counter >100)
{ fprintf (case counter{something})}; how do I do this?

View 11 Replies View Related

C/C++ :: Write BST To File

Nov 12, 2014

I can only write one value to file:

get all, say for example barcode
char* bst:: get_bar(hwareItem*& root){
while(root!=NULL){
get_bar(root->left);

[Code]...

gets only one value depending on traversal orderI wish to get all values of BST

View 1 Replies View Related

C++ :: Using Outfile To Write Name?

Sep 4, 2013

I am trying to display my name using outfile vs. cout and I get errors I don't know how to fix. Here is the code:

//This program will calculate the monthly payment, the total amount paid back over the entire life of the loan,
// and the total interest paid over the life of the loan.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
ofstream outfile;

[code]....

And here are my errors:

1>z:csci207program1practice.cpp(13): error C2297: '<<' : illegal, right operand has type 'const char [16]'
1>z:csci207program1practice.cpp(13): warning C4552: '<<' : operator has no effect; expected operator with side-effect

View 1 Replies View Related

C# :: Write Five And Convert To Int

Jun 10, 2014

i'm using TryParse to convert 5 in string to 5 int but i want to give the possibility to the user to write five not 5.

View 5 Replies View Related

C# :: Write WPF With Textbox

Mar 28, 2015

I was following a c# book to write a WPF with a textbox. When the textbox is selected(got focus) with keyboard or mouse, it will select all text in it. I followed the book and wrote this:

private void TextBox1_GotFocus(object sender, RoutedEventArgs e) {
TextBox1.SelectAll();
} private void TextBox1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
var control = sender as TextBox;

[Code] ....

The book said having "e.Handled = true" is to stop the event in order to prevent the cursor being positioned on somewhere of the text instead of selecting all text. From my understanding, "e.Handled = true" is for stopping routed events. Is this means that something will run if "e.Handled = true" is not there? If yes, then what is it?

View 2 Replies View Related

C/C++ :: Why Write Return 0 At The End

Jan 22, 2013

#include <iostream.h>
#include <conio.h>
int main ()
{
cout << "Hello World";
getch();
return 0;
}  

In the above code, why is it necessary to write getch() and return 0? What is their purpose?

View 7 Replies View Related

C++ :: Write In Log File Through DLL

Apr 26, 2013

so i have this dll with a DBTProc, whenever a window gets created i want to write something in a log file. Now everytime I run it it adds three times the text in this log file, but then it does nothing anymore. I do hear a beep everytime a window get created so it doesn't actually open my file to write in

code:
LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam)
{
if (code < 0)
{

[Code].....

View 7 Replies View Related

C++ :: Write A Calculator Using Two Stacks

Apr 13, 2014

I just started by defining a stack class (stackDouble). I need to write a program that accepts an infix calculator expression, with the following operators (**, exponentiation, /, division, and, -, subtraction. The operator precedence is exponent, division, and subtraction.I need to use a stack of doubles and a stack of strings, of which I can write two classes, or write a single stack template. The user will input the expression just via cin, and there will be a # before every number, a ! before each operator, and a . at the end of the expression. '#', '!', or '.' can be input into a char variable, numbers into a double variable and operators into a string variable.

For example, the following would output 6:

# 3 ! / # 2 ! / # .5 ! ** # 2 .

As stated above, I already made up a stackDouble class. What would I need to do to create the other class (I don't think I want to do it with a template)?

Code:
#include <iostream>
#include <string>
using namespace std;
class stackDouble{

[code]....

View 2 Replies View Related

C :: Read / Write To File

Mar 3, 2013

How can I erase the data stored in /tmp/a.txt after every run of this code?

Code:

#include <stdio.h> // IO operations
#include <unistd.h> //for pid, ppid, fork functions
#include <sys/types.h> //for pid_t type, kill function
#include <stdlib.h> //for exit function
#include <signal.h> //for kill function
#include <sys/types.h>
#include <sys/stat.h>

[Code]...

View 3 Replies View Related

C :: How To Write Powers Without Using Math

Sep 22, 2014

How would one write 3^i without using .math? (i being numbers 0-9)

More specifically, this is what I have:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x, n, answer1, first;
x = 3;
n = 10;
first = 1;

[Code]....

And this is what I want it to produce:

1 0 1.0
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805

I believe I am only having troubles with the first column,

View 10 Replies View Related

C :: How To Write Scanf With Right Parameters

Jun 30, 2013

How can i upgrade my program I want to input a octal and binary number and convert them in base 2, 8, 10, 16..

how can I write the scanf with the right parameter in it??

Code:
scanf ("%x",&i); Code: #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main() {
int i;
char buffer [33];

[Code] .....

View 5 Replies View Related

C :: Write A Program That Would Open A PDF?

May 10, 2013

I have a batch of .pdf files (~1000) with names 001.pdf 002.pdf ...etc. Still pretty new to C, but would it be possible to write a program that would open a PDF, prompt a new name from user, and when entered, close the .pdf and open the next one in the list?

View 14 Replies View Related

C :: Data Read And Write

Dec 22, 2013

My program needs to receive data continuously from one process and the received data is read continuously by another process.But when I am trying to create a pipe using mknod on fat32 file system in linux , it throws an error saying "mknod: operation not permitted".

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved