C :: Scanning CSV File And Assigning Variable To It

Dec 26, 2013

How to scan a CSV file and assigned variable to each of the integer scanned in a csv file

an example of the csv file:
0001,40,,10

How do I scan the CSV file and assign 0001 to variable student id, the 40 to variable module 01,the 1 without input entered to module02 and 10 to module03

View 6 Replies


ADVERTISEMENT

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++ :: Assigning Reference Variable To Another Of Same Type

Jun 4, 2012

What is wrong with assigning a reference variable to another reference variable of the same type? I guess I have not understood references very well.

1- In below code, the initialization list gets error because agent "object reference variable" cannot be initialized with a reference variable of the same type.

Code:
class Intention {
public:
Intention(Agent& agent,int Id, string name);

[Code] ....

In other places I have the same problem. In below code the assignment gets error (no overloaded function for assigning a reference to another reference?)

Code:
void Agent::setWorld(World& world) {
this->world = world;
}

//Note: this->world has a type of World&

2- In this other one, I want to assign reference of a vector member to a reference variable of the same type.

Code:
vector<Intention> intentions;
...
Intention& currentIntention = intentions[intentionsIterator]

View 6 Replies View Related

C/C++ :: Scanning CSV File Into Array Of Structs

Mar 18, 2015

I need to scan a .csv file that contains the following info:

programming,03,60,141,01,W,2015
programming,03,60,141,30,W,2015
Algebra,03,62,102,02,S,2013
Religion,08,98,938,20,F,2014

So i made a struct:

typedef struct CourseInfo {
int courseID;
char courseName[50];
char courseCode[13];
char term[7];
} courseinfo;

Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:

int main() {
FILE *p;
p = fopen("input.csv", "r+");
if(p == NULL) {
puts("The file could not be opened");

[Code] ......

But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:

int main() {
FILE *p;
int lines = 1;
char ch;
p = fopen("input.csv", "r+");
if(p == NULL) {

[Code] .....

But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.

View 11 Replies View Related

C :: Assigning Array With A Variable Number Of Elements

Jul 18, 2014

I have a simple problem about memory allocation.In the function Nr_elements() i assign a value which represent the elements of array. The pointer p is initialised with the address of variable n, but when i compile i dont know why but dont work. This function return a pointer.

Code:
#include<stdio.h>
#include<stdlib.h>
int *Nr_elements();
int *allocate(int);
void deallocate(int *);
[code]....

View 3 Replies View Related

C/C++ :: Assigning Variable From Multiple Choice Answer

Oct 29, 2014

I tried to create a multiple choice list and I want to assign the value of the answer option chosen by the user so I can use it later on in the code. Later on in the code i've asked how many people (p) want a drink and multiplied it by the chosen size to calculate the price c = p * n where c is cost, n is price and p is number o of people At the bottom i tried to assign parameters where depending on what option the user has chosen n will be assigned to the chosen value...

{
printf("SELECT TYPE OF PAINT:"); /*multiple choice of paint */
printf("1. Large ");

[Code]....

View 1 Replies View Related

C :: Scanning A File With Words And Int / Float Numbers

Dec 1, 2013

scanning a file with both words and INT's/Float numbers. This is the file data here.

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99

[Code]...

What I'm focused on is reading in the first three numbers which I already have with fscanf and then reading in BUY TICKET with the digit afterwards. My problem is that I don't know how to reach that part of the file without scanning in something I don't want to. Also, how would I scan the number after scanning BUY TICKET? Would it be something like using %s and %d right afterwards?

View 4 Replies View Related

C++ :: Scanning A Header File To Save Image Data

Jun 11, 2013

I'm trying to read from a header file to take the image dimensions and other variables but I don't understand how to iterate through the "key" so it saves each line.

This is what the header file will always look like:

!INTERFILE :=
!imaging modality := nucmed
!version of keys := 3.3
;
!GENERAL DATA :=

[Code].....

Ideally it would just skip the keys that aren't wanted and keep moving through the lines. Should there be a for loop for the key (and if so, how does that work with pointers?) or should this method just be scratched...

View 6 Replies View Related

C :: Scanning Numbers From TXT File Into A File

Mar 6, 2015

I'm new to programming and I have a question about scanning numbers from a .txt file into a .c file. I have an array that has 50 integers and I want to read in 50 numbers from a .txt file. What would I type in on the command line to get the array to read in the .txt numbers?

View 1 Replies View Related

C :: Assigning Line Of File To String

Mar 28, 2014

I'm making a game that requires the user to enter a correct username and password to play. I have a list of accepted ones saved in a txt file. How do i read each line of the file and check it with the one entered? I know how to use strcmp(string1, string2). I just need to know how to move from one line to the next. This is what I have for this part of the program so far. Also, I think im using the feof() wrong.

Code:
id = fopen("F://CS223/namepass.txt", "r");
score = fopen("F://CS223/scores.txt", "a");
srand(time(NULL));
if(id == NULL)
{
printf("ERROR");

[Code] .....

View 6 Replies View Related

C :: Reading Values From File To First 2 Columns Of 2D Array / Assigning 0 To 3rd Column

Apr 4, 2014

I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.

I'm not sure for instance why on the bottom loop for line 1 it doesn't print:

temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1

Code:

#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");

[code]....

View 8 Replies View Related

C# :: How To Multithread Port Scanning App

Jan 24, 2012

I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.

I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.

Code:

private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);

if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }

I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.

View 3 Replies View Related

C :: Scanning 2 Strings In Same Scanf Call

Nov 20, 2013

Somehow only str2 is successfully scanned and str1 is not printed

Code:

printf("
Please enter two times in this way xx.xx xx.xx now ");
scanf("%s%s", str1, str2);
printf("
%s - %s:
", str1, str2)); result : - str2:

View 3 Replies View Related

C :: Scanning Characters Into A Multidimensional Array

Mar 19, 2014

I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"

The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?

View 4 Replies View Related

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies View Related

C/C++ :: Error In Scanning Database Names

Feb 13, 2014

I'm working on a program to store student's names, ID, and GPA, but for some reason the first and last name of the student are copied into every name of the database array once I scan them, regardless of whether or not add_student even runs.

typedef struct{
char *f_name;
char *l_name;
int stud_id;
double gpa;
} student_t;
int add_student(student_t db[], char fname[], char lname[], int iden, double grade, int db_size){
int i, error;

[Code] ....

For example, if I type "a Adam Johnson 1234 4.00" it'll add the first student with name Adam Johnson. However, if I try to add another student named "Kyle Walker", it overwrites "Adam Johnson" with "Kyle Walker" as soon as the names are scanned.

View 3 Replies View Related

C :: Scanning 2 Dimensional Array For Duplicate Values

Mar 26, 2013

I am trying to scan a 2 dimensional array to see if there are any duplicates within a row or column; i.e. the concept of a sudoku game.how to scan a row or column one at a time.

View 1 Replies View Related

C :: Scanning Words Into Binary Search Tree - No Stack Error Diving Seg Fault

Apr 2, 2013

This is the first time I have encountered a "no stack." error giving me a seg fault. Anyhow, I am scanning words into a binary search tree and it is giving me a seg fault.

Here is the file (words.txt):
4
bravo
alpha
gamma
delta

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct node_t{
char *word;
struct node_t *left;
struct node_t *right;

[Code] .....

View 5 Replies View Related

C :: How To Share Variable Value From One Source File To Other Header File

Dec 11, 2014

I wanted to share the value of a variable from Sender Program to Receive after program and want to calculate difference between send and receive. After studying Header file concept I program following three.

Now I am struck. How to to compile? I link all these file. I used following method:

Code:
gcc Sender.c -o Sender Sender.h
gcc Receiver.c -o Receiver Student.h

Then I run Sender and after that Receiver.I per my knowledge, Receiver should give difference but it gives error :

Code:
Receiver.c: In function "main":
Receiver.c:10:42: error: "Send" undeclared (first use in this function)
printf(" Total Receive is %d
",Receive-Send);

Code:
Sender.c
#include <stdio.h>
int Send ;
void main(){

[Code] ....

View 2 Replies View Related

C++ :: Read Txt File With The Name Is Variable?

Feb 27, 2013

i want to load txt file, but the name of txt file is variale.

my code is error!!!

String ^ s;
s="t";
ifstream txt (s+".txt");///error

im a beginers!!

View 2 Replies View Related

C++ :: Using Variable As Name For Combined File?

Apr 27, 2013

I have been researching how to use the prefix of a user input file name as the prefix of an output file name for a combined file. "Adding two text files into one text file", but the combined file name is entered directly, not from a variable.

std::ifstream file1( "file1.txt" ) ;
std::ifstream file2( "file2.txt" ) ;
std::ifstream file3( "file3.txt" ) ;
std::ofstream combined_file( "combined_file.txt" ) ;
combined_file << file1.rdbuf() << file2.rdbuf() << file3.rdbuf() ;

My code already has the user input file name as a variable. I would like to insert the prefix of that variable in line 4 with a new suffix.

I also found this code in an archived post by Duoas on May 31, 2010, "Changable filename based on user input," but I don't know how to adapt it to my combined file.

#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
ofstream f;
string filename;

[code].....

View 4 Replies View Related

C++ :: Creating Variable Name For Binary File

Dec 11, 2013

I'm attempting to split a large binary file into smaller manageable files for analysis. I've written most of the software but I'm stuck in a couple of places.

1. The binary file is split by looking at a couple of bytes to determine when to create a new file or continue appending to the current new file. The question is when I need to create a new file, how can I dynamically sign it a name? My intention is to rename each subfile by: "original_name" + new section id + ".log".

2. The start of each section is determined by a specific pattern (6 bytes of FF's). I'm running into an issue where the pattern check is checking for 5 bytes instead of 6 because the for..loop doesn't increment for one instance.

I've attached the code I have so far.

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;

int append_to_file(FILE *f,long sec_start, long sec_end)

[Code] ...

View 2 Replies View Related

C++ :: Opening File Using Variable (Char Or Int)

Mar 14, 2013

Can we open a file in c++ using a variable(either character or int)?

View 1 Replies View Related

C++ :: Trying To Substitute A Variable For File Directory

Jul 1, 2014

I am trying to substitute a variable for the file directory. Here is the error: error: no matching function for call to 'std::basic_ ofstream <char>:: basic_ ofstream(std::string&)'

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
using namespace std;

[code]....

View 2 Replies View Related

C/C++ :: Access Variable Using Extern In A Particular File

Sep 2, 2013

I have 3 files: f1.c f2.c and f3.c

I have declared variable int a; in f1.c and int a; in f2.c.

Now I want to use the variable int a; in f3.c . But this variable corresponds to the variable in f2.c .

View 4 Replies View Related

C++ :: How To Reference Static Variable In Another File

Apr 15, 2014

I've got a static variable in the master file called :

static dtNavMesh *g_navMesh;

I just need one copy of this object.

In another module, I need to reference this global variable.

extern dtNavMesh *g_navMesh;

View 5 Replies View Related







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