I'm supposed to read in a data file with fixed length records and fields, create a sorted index list in memory, and save that list to a file. Then I'm to write a second program that interactively (via the Linux command line) takes a key and the index file name, opens and loads the index file, searches for the given key using the index table, and opens and returns the correct data record.
The original file consists of a list of records with a key (int), a name (string of 8 characters max), a code (int) and a cost (double).
The RRN (relative record number) begins at 1, with the RRN at 0 representing a dummy record with only the size in the first entry.
The "File is Open" part will be replaced once I figure out what do do once the file is open, just used this message to verify that it was opening the file.
I'm working on a project where I have the user enter storm data about hurricanes for multiple seasons. I need to make separate arrays for:
1. the month, wind speed, and min. press. 2. the category of the storm
What I'm having trouble understanding is how to make the software take an input, assuming from a scanf, and put it in an array. Then taking that value and output-ing it back out when needed.
So here is piece of my code. Note: Disregard the commented sections of the code, my current project is building off a previous one, where in the last project we were using loops, now we are using arrays.
In the code above, how exactly the scanf takes the inputs from the user and then stores them for me to access. So, I want my array to be 3 columns, for months , wind_speed, & minpress. The array has a undetermined amount of rows. I think if I figure out the first array, I can handle the second.
I've recently been learning GTK (though this question is not specific to GTK), and came across a situation that I was unsure how to best handle. Essentially, I've defined several pointers in one source file, and I want to access those pointers from other source files.
The structure of my GTK programs generally follow this pattern:
- "main.c": Define the main window and run GTK main - "create_window.c": Create and arrange widget pointers in the main window - "program_functions.c": All other source code for the project (several source files in reality)
In "create_window.c", I declare and define all my widget pointers (e.g. label). If I need to modify those widgets in "program_functions.c" for any reason (say, to change the value of a label), I need access to the pointers created in "create_window.c".
My first thought was to create a global struct of pointers in "create_window.c", and extern that struct to the other source files that need access to the pointers. The thing I don't like about this approach is spreading globals across my program.
My second idea was to create access functions in "create_window.c" where the necessary pointers are statically stored. The first time I call this function (immediately after creating a widget), a static copy of that pointer is stored in the function. Each time afterwards when I call that function (from other source files), I simply use that static pointer to access the widget of interest.
I have a big un-editable program, A, which I need to run for like a 1000 different input files. It takes about 15 minutes for each file, so a little parallelisation wouldn't hurt.
I have installed openmpi and it works fine. I have made a small program, B, which selects an input file, moves it to another directory, calls program A with the path to the selected input file and then - when A is done - selects a new input file etc. It should loop until there are no more files in the initial directory.
The problem is this: When I have several processors they might pick the same file and that leads to errors. I have a working program, but it is not pretty.
Code:
#include <stdio.h> #include <mpi.h> #include <dirent.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]) { int num_procs, procs_id, i, exit; struct dirent *ent;
[Code]...
Every time a processor tries to move a file that another processor has just moved, the output shows an error message before looping to the next file and trying again. It works, but it is a bit annoying. So my questions are:
I currently have a running program "game.cpp" that runs a game of tic tack toe. I want to split the working functions into header files so that game.cpp isn't so cluttered. I have created two header files "displayBoard.h" and "gamePlay.h" but they wont compile because the functions are looking for variables that haven't been declared. First, here's the working code.
#include "displayBoard.h" #include <iostream> #include <limits> //This is required to catch invalid user input class ticTacToe //A class to contain all our functions {
I am trying to create n number of files (n being an integer), by passing the name through a character array (and obviously changing its value at each iteration). But the problem is that the program compiles and executes but not a single file is created.
Here is my code snippet.
void file_phipsi(int m) { int a=0,n=0; char *str1;
I can't get c++ compilers to create or open files with a string input, even though the compiler accepts a file name in "quotes". How can I get this compiled (I am downloading a series of file names which I need to load into a consolidated file).
My coding (the commented line works, the string example does not).
//indirect file open example #include <iostream> #include <fstream> #include <string>
I am new to C programming, I have been given an assignment to create a simple calculator by splitting the program in 3 files. It should have 2 .c files and 1 .h... I went through the internet extensively and could only come up with this.
main.c:
Code:
//Calculator main.c #include <stdio.h> #include <conio.h> #include "Functions.h" int main() { float x = 0, y = 0; int operation;
[Code]...
Functions.c
Code:
#include "Functions.h" extern float x, y; float addition (float a, float b) { return a + b;
[Code]...
Functions.h
Code:
#ifndef FUNCTIONS_H_INCLUDED #define FUNCTIONS_H_INCLUDED float Sum(float a, float b); float difference (float a, float b); float remainder (float a, float b); float product (float a, float b); #endif
When I do a 'cl main.c' on the Developer Command window for VS2013, i get an error that reads :
main.obj main.obj : error LNK2019: unresolved external symbol _difference referenced in function _main main.obj : error LNK2019: unresolved external symbol _product referenced in function _main main.obj : error LNK2019: unresolved external symbol _addition referenced in function _main main.exe : fatal error LNK1120: 3 unresolved externals
I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
The program is as follows:
Code:
#include <stdio.h> #include <stdlib.h> int main(void){ char hostfile[75], hiddenfile[75], hiddenFileName[15] ; printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: "); scanf("%75s", hostfile);
[Code]...
The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
I could trace the above one of the mistakes where the array initialization is crossing the array limits and writing into array[32] which is not available. My question does it overwrite into array1 as it is declared below array or it can write into any other location.
Code: using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Chapter7Problem13
[Code] .....
I keep getting an out of bounds error in my code
I'm suppose to enter number of orders then enter those orders then calculate a discount and net price display the orders, discount, net price then the totals at the bottom ....
I want to get the starting index of structure elements, whoz id are 0,1,2,3 Like in below code col_data[0] (starting id=0) col_data[3] (starting id=1) col_data[5] (starting id=2) col_data[8] (starting id=3) Code:
Code:
typedef struct gg{ int id; int value; }
[code]....
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?
I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.
Prototype should be something like
int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements
I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mind_Puzzle { public partial class Form1 : Form
[Code] .....
When i try to start it, it doesn't start or it gives an error on "UsedList[i] = false;".
The error: "An unhandled exception of type 'System.IndexOutOfRangeException' occurred in Mind Puzzle.exe
I am suppose to make a value to attach to a array and then have it stop on the last one with an error if it were to go past (done more or less).
Problem is I am suppose to use a int to hold the value of the array and then add 1 each time but my question is, if you were to add another number to increase your current array slot, what would that look like as I image that going array[0] + 1 isn't going to make it array[1].
I need understanding the logic behind this function. The function is supposed to "Return a pointer to the character at the index given" . For example, what exactly are we declaring at "(char * const c, int index)"? where does "index" come from or equal to in the body of the function?
Code: 1 2 3 4 5 6 7 8
char * GetValueAtIndex(char * const c, int index) { int i = 0; char *p = c; while (i++ != index) p++; return p; }
Im problem with parsing. I read file line by line and i store another class bu when i parse the line last word gone example "I study algebra and discrite math" math didnt store.Why ? i want to calculate index section for document how can i solve this problem??
my question is located as a comment beside the last printf ! ? check the comment near the last printf the comment is ==>here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?
Code: #include <stdio.h> #define N 30 #define n 100
[Code]....
here i get a sequence of numbers the question is how can i copy this sequence to an array and the print the array out ?