If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?
For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?
Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);
Repeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.
I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.
Code: #include <stdio.h>#include <string.h> #include <ctype.h> #define MAX 100 int checkvowel(char c)
I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:
Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().
I have a VC++ 6 dialog-based application. This application is intended for reading data from a USB device (this is a FTDI FT245R chip). I have a start button on the dialog. On clicking it, unsigned char data retrieved from the USB device is displayed on the dialog. The start button invokes a function which includes a while (1) loop inside which the USB device is read and the values displayed.
There are no break or continue statements inside the always operating while (1) loop. All this works fine. My problem is how do I exit the application as normally it would just run forever? I have put an exit button on the dialog with code added to call OnOK(). Normally this would nicely close the application but as I have an endless while loop in my application so this button doesn't seem to work. Nothing happens on clicking it and clicking it repeatedly just hangs the program.
#include <stdio.h> int main(void) { int c; int inspace;
[Code]....
I tried this code w/o no "inspace" in it and code still worked but if I made more than one blanks between words it happened vertically double newlines etc.. so I just wanna know how this "inspace" makes newline w/o blank line for each word. Is that a flag ?
I'm having a little trouble writing program that on remove all repeat characters and leave only the non repeated characters. This is want I have so far.
In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:
Code: #include "std_lib_facilities.h" int main() { int number_of_words = 0; string previous = " "; // previous word; initialized to "not a word" string current; // current word while (cin >> current) // read a stream of words
[Code].....
The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).
Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all.
I create a loop that would repeat itself many times a second? Trying to do extremely basic graphics with a grid and system("cls") every time I run a command, but it still looks very jumpy. I realize system calls are evil. Any way to get rid of this too.
I created a very basic program which contains a vector (my vector) that holds 0, 1 and 1. This program compares each element in the vector. If the element after the one currently being compared is equal to it, it outputs "repeat found!" Now this all works perfectly, but my next step was to erase the repeated one. Everything was working up until the delete step. I get a weird error that says "vector iterator not dereferencable" .
// vector::begin/end #include <iostream> #include <vector> using namespace std; int main () { vector<int> myvector;
I have a method that changes a canvas color after set intervals, e.g. start timer, 5 seconds green, 3 seconds red, then stop. This functionality is provided in the interval method. The problem I'm trying to achieve is getting this sequence to repeat for a set number of iterations.
I tried to solve this by setting up a counter after the timer is stopped but the code keeps repeating indefinitely by starting and stopping over and over instead of the max of 6 iterations I had set. In debugging the problem, I watched the value of 'i' and when the 'if' statement is set to false. The 'if' statement gets set to false after 7 iteration as expected but the start(); keeps getting called.
void myTimer_Tick(object sender, EventArgs e) { //Assign text box string value to a time span variable. TimeSpan workTm = TimeSpan.ParseExact(wrkString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture); TimeSpan restTm = TimeSpan.ParseExact(rstString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture);
// update the textblock on the display // with hh, mm, ss, ms ms = myStopwatch.ElapsedMilliseconds;
I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").
I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:
Code: #include <cs50.h> #include <stdio.h> #include <string.h> { // get user input printf("Type a sentence: "); string s = GetString();
[Code] .....
The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.
I am currently working on writing a word search program. However, I am stuck on reading the used input into the 2-D array. The code I've posted below is only dealing with the user input (I'll work on the word search part once I know i am correctly reading in the user input). I know the coding is bad practice with the use of hexadecimal, and getchar() ect. But I am currently using a microblaze microprocessor and this is just the way microblaze can interpret the information. As for the infinite while loops...that can be changed just trying to figure out how.
My question is how could I change my code to correctly read in the user input into the 2-D array?
Code: #include "platform.h"#include "xparameters.h" #include <stdlib.h> #include <stdio.h> #define MAX 20 int main() { char grid[MAX][MAX], word[30]; int i, j, arr[2],num;
Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.
I'm having trouble receiving that random word and I'm getting the definitions from the file.
This is what is in the words.txt file apple#the usually round, red or yellow, edible fruit of a small tree boat#a vessel for transport by water horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding television#a system for transmitting visual images and sound that are reproduced on screens soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc. bottle#a container, typically made of glass or plastic and with a narrow neck barber#a person who cuts hair toast#sliced bread browned on both sides by exposure to radiant heat radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects red#of a color at the end of the spectrum next to orange and opposite violet
I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.
Here is my code for a simple game. paste it and try it.
#include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; int main (void) { stringg[4],
[code]...
What they do (enter 4 actions)?
"; for (int ai = 0; ai < 4; ai++) getline(cin, a[ai]); cout << "
Where is happening (enter 4 locations)?
"; for (int li = 0; li < 4; li++) getline(cin, l[li]); for (int c = 0; c < 4; c++) cout << g[rand() % 4] << " and " << b[rand() % 4] << " are " << a[rand() % 4] << " from a " << l[rand() % 4] << endl; return (0); }
At the end in the 4 lines some of the names, actions and locations repeat. How do I make them to not repeat and use every name that you will enter? do I need random_shuffle? How can I integrate it in my code?
I have an array matrix called tmat,,and i know that in every row of tmax there are values which repeat two times...and am writing a code to extract the values WHICH DOES NOT REPEAT into another matrix called tcopy...the codes compiles fine...and it writes nicely to file...but without the desired result...
One last question...how can i get the array tcopy written to file in the form 5x3...and not all the figures in line one after the other? i mean i wish to see the matrix like a matrix on file..not like a list of numbers....
Code: #include <iostream> #include <fstream> #include <vector> using namespace std; const int R = 5; const int C = 5;
i want to create a program (in c++ or c#) that will play mp3 files but also display a word file with the lyrics of the mp3 song playing. so if i choose a mp3 file from a list, the lyric file for that song should also be displayed. i have all the mp3 and lyric files saved on the computer so my problem is how can i link the files?