C :: Program Crashes When Parsing Musical Notes From It
Jul 23, 2013
I have the text parser done, but when I use it, the program crashes. Just because of how I test my code, I know the section where it occurs, but I'm not sure what the exact problem is ( no errors or warning, so it's just something I don't see ). Here is the full code
I probably made a mistake in the way I allocated memory or tested values, but I'm not sure where it is in my code. Currently it just prints out "Failed to parse data on line 1" then crashes. Here is the text file I give to this program.
Is this a good way of writing this program?I wanted to start fresh with my new code though and a better title.Basically, I took what I learned from my questions in that thread and managed to build a list of musical notes( octaves, frequencies, sharp symbols, basically everything ).
Code:
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> #define MAX_NOTES 88 /* 88 keys on a standard piano */
[code]...
I already know the frequencies are correct( they are rounded, but they should be close enough to the value ), but I wasn't so sure about the note labels. Obviously though, I'm not done with this program and I will be adding most of the functions Anduril suggested to take a text file and convert it into music. I just wanted to make sure I had everything correct before moving on. I probably didn't do the GetNextOctave() and GetNextNote() functions very efficiently so need suggestions on those functions also.
so my homework assignment is to make a program of which removes any notes in a program file.
for example, you run my program it will ask for a filename, when entered it opens the file, copies everything in it and removes any double forward slashes (//) and anything after that up to the new line character ( ) and anything between /* and */ including the /* and */.
i created the entire program and it removed the // and anything after that up to the new line character but will not remove anything after the first / when it finds a /*. This includes the */ at the end of the comment.
the section of code that removes the comments is
//this loop removes all notes for(i=0;i<buf.st_size;i++) { if((filecontent[i]=='/')&&(filecontent[i+1]=='/'))//removes notes using // { for(i=i;filecontent[i]!=' ';i++) filecontent[i]=' ';}
[Code]....
i know that the section that removes the multi line comments would not remove the final */ at the end if it did work, i was planning to fix that later once it removed the comment.
How we will write a program that will count a number of notes. I mean if i have 5676 rupees and i want to find the number of 5 thousand pak currency ,the number of 1000 notes, the number of 500 notes and the number of 100 notes. How we design such a program of if rlse structure to perform the above task.
In my program, I am trying to implement a set in which I can add/remove and print, it doesn't have to be a specific value removed just that it removes an item from the list. When I call the removeItem function it crashes, saying my iterator is out of range. I don't understand what is wrong. Here is my code:
I've implemented a records system for a college assignment and everything works as intended. However upon increasing the amount of records to store in my array above 10, the program crashes upon adding a new employee and I can't work out why...
Problem: When I add a new variable to complete my program, it crashes. I have tried tracing where the problem is but it leads to adding new variables
Purpose of program: Every 2 lines of the input file belong to 1 participant. The line with decimals include times a person has run miles. While the second line of each participant are integers that indicate the best sets from workouts the participant had done.
so an example of the output
Participant #1 Cardio Workouts: Best Time: Worst Time: Average Time: Weight Workouts: Most Sets: Least Sets: Average Sets:
Participant #2 ...
Why my program is crashing
#include <stdio.h> int main () { // Stats Col0=BestTime Col1=WorstTime col2=mostSets col3=leastSets Col4=Average_time Col5=Average_sets float chart[20][12], stats[10][6], best_time=100, worst_time=0, most_sets=0, least_sets=100, avg_time, avg_sets, sum; int i, j; int p=0;
I have a local student and international student class inherit from student class. read and print are virtual functions. After i have set all the member variables when i wan to print out all the student information, my program crashes.
Code: int main() { clsUniversityProgram objProgram[3]; for (int x = 0; x < 3; x++)
My programs complies and runs. However, whenever i try to enter something when prompt to enter the number of accounts i wanted to create my program crashes.
By the way, im using codeblocks.
it says
terminated called after throwing an instance of 'std:: out of range'. what(): basic_string::substr"
Code: #include <iostream> #include "clsInterest.h" #include "clsDate.h" using namespace std;
I'm trying to code a Singly-Linked List(Double Pointers) selection sort program and I can't tell what the problem is. My compiler says no errors but when I run the program, it crashes right after I enter the values.
#include <iostream> #include <string> #include <limits> //for std: numeric limits #include <algorithm> //Function to get an integer from the user that is greater than or equal to zero.
int getPositiveIntFromUser(const std::string& prompt) { int retVal = -1;
[Code] ....
The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!
I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.
I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...
I have written a MFC dll to interact with an API and it is run by the target program. the first 100 bars are drawn properly but then the program ceases to operate. I am guessing I have a memory leak but I probably just dont understand what I am doing as I am quite new to programming MFC GDI. Here is my code that causes the trouble...
The variables coming in are commented out to facilitate testing and so it would be displaying the same bars over and over because of this. it worrks for 100 bars, then crashes.
void MainDlg::SS_UpdateChart() { // the chart plot is completely recalculated each time a new bar is shown // 300 is plottable height // 400 is plottable width, 39 bars int displayChartHeight = 300;
You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.
The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.
Write a driver to test the permute class to pass in any two strings of any sizes.
Other than mention in the following, you can add more classes, functions, and private data members to this program.
Note class
The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.
Permute class
The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.
There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.
Driver file
The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.
first = "", second="", first = "", second ="CATMAN", first = "C", second ="ATMAN", first = "CA", second ="TMAN", first = "CAT", second ="MAN", first = "CATM", second ="AN", first = "CATMA", second ="N", first 1 = "CATMAN", second ="";
I'm new to c++ and I want to create an infinite sheet on which a user could be able to write notes and place images. Any GUI library that I could use to do that?
You need to write a permute class that will take first and second strings to rearrange letters in first, followed by second. For example, if the first is “CAT” string and second is “MAN” string, then the program would print the strings TACMAN, ATCMAN, CTAMAN, TCAMAN, ACTMAN, and CATMAN. The first and second strings can be any length of string or a null.
The permute class uses a Note class as link list note to link all letters arrangement. The permute class has Note pointers, firstNote and lastNote, to point to the beginning and ending Notes of the link list as private data members. There are three other private data members (total, firstString and secondString) to store the total possible number of arrangements and strings pass into the class.
Write a driver to test the permute class to pass in any two strings of any sizes.
Other than mention in the following, you can add more classes, functions, and private data members to this program.
Note class:The Note class needs to have two private data members and a constructor. The two private data members are data and p pointer. The data’s data type is string and p pointer is Note. The Note class constructor has two parameters, one is string and the other is Note pointer.
Permute class:The Permute class has five private data members (*firstNote, *lastNote, total, firstString and secondString). The firstNote and lastNote pointers are point to Note. The total has integer data type. The firstString and secondString have string data type.
There should have at least three public member functions, Permute, permutation and print. The Permute function is the constructor which takes strings to initialize the private data members. The permutation function does the recursive call to arrange the strings and setup the link list. The print function will print out the private data member information.
Driver file:The driver file should declare a Permute eight elements pointer array. Instantiate eight Permute object with the following eight set of data and assign the object to the pointer array. Use a repetition to call the object’s print function to print out the private data member information. If the total of the permute private data member is less than 100 then print out the permutated letters four in a row, otherwise print out 9 in a row.
This has happened before, when I try to run a code it will say "blah.exe has stopped working" and I would have to change the code in some way to make it work.
So I've been working on a sorted linked list homework assessment and I've been stuck on a problem for a while now. Below is my code for inserting a new object into the linked list, for some reason it keeps crashing whenever I try to malloc temp. (between the "checkpoint" and "after malloc" printf statements) .
Code:
int SLInsert(SortedListPtr list, void *newObj){ SortedListPtr curr = list; SortedListPtr temp = NULL; if(list->obj == NULL) /*if the list is empty insert obj into the first node*/ { list->obj = newObj; free(temp);
I randomly get this when I execute my program. Sometimes it happens three times in a row sometimes it can go about 10 times before it shows up again.
I was not able to find out what the error code means, and I can't pinpoint the error. During debugging it NEVER happens, and logging tells me it happens between two cout << operations.