C :: Fscanf Data And Delimiters
Dec 7, 2013
How would I fscanf this piece of data?
Delimiter is --> :
VS1234567890654327:Rob Fordfirst:001:200
VS1234567890654312:Steven Harper:200:010
Code:
while(3==fscanf(filename, "????", &string[size], &name[size], &number1[size], &number2[size])) {
//printf("%s - %s - %.3d - %.3d", string[size], name[size], number1[size], number2[size]));
size++;
}
View 6 Replies
ADVERTISEMENT
Apr 17, 2014
I am a very fresh c programme user, in fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code? When I printf the array it always ends up with random numbers.
Here is my code:
#include <stdio.h>#define SIZE 2
#define count 2
int main()
{
[code]....
and the file i am trying to read from :
Code:
1, 2, 3, 4
5, 6, 7, 8
8, 9, 10, 11
I am trying to scan a list of 3 by 4 numbers and the 4 numbers of each column to the 4 different arrays, so if I read from the data above, i get an array with numbers 1,5,8; another with 2,6,9 and so on. Is it how its done in my code?
View 2 Replies
View Related
Apr 16, 2014
I am a very fresh c programme user, and need to fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code?
When I printf the array it always ends up with random numbers. Below is my programme which is just designed to read a doc and print it back out, as well as the text doc it is designed to read.
View 3 Replies
View Related
Mar 19, 2013
This is part of a bigger program im working on that deals with data structures, but I'm trying to figure out a way to tokenize a long file of purchases that is being read to my program. I rewrote the program to pinpoint my problem. I need to get the name, cost, item and quantity from this string. I figured out how to look for the cost, but what about the name and item(shirts)? How can I do this all in one loop because there are multiple strings and i'm gonna eventually send all the info to a data structure for each person(name)? I'm only asking about the tokenizing part, but this code works for the cost.
Code:
int main(void) {
char myString[] = "Angela bought 9 shirts for $6 each." ;
char * del = " " ;
char * token ;
[Code].....
View 12 Replies
View Related
Apr 21, 2013
I have a file that looks like:
Student ID:88152; Grades: 83.67, 92.45, 74.43, 97.95, 76.45; Name:Abercrombie, Neil
Student ID:92485; Grades: 77.65, 92.31, 60.47, 67.12, 99.64; Name:Aderholt, Robert
Student ID:10623; Grades: 37.95, 83.11, 64.46, 74.76, 95.30; Name:Alexander, Rodney
Student ID:76793; Grades: 53.13, 81.02, 83.71, 90.75, 88.92; Name:Baca, Joe
I need to read the id numbers into an array, the grades into a 2d array and the names into a 2d c-style string arrays.
But i'm having trouble getting past the delimiters
This is what i'm trying but it doesn't work
fin >> dummy;
fin >> id;
fin >> dummy;
fin >> grades;
[Code]....
View 1 Replies
View Related
Apr 22, 2013
I want to use getline to read stuff from a file that looks like:
Student ID:88152; Grades: 83.67, 92.45, 74.43, 97.95, 76.45; Name:Abercrombie, Neil
Student ID:92485; Grades: 77.65, 92.31, 60.47, 67.12, 99.64; Name:Aderholt, Robert
Student ID:10623; Grades: 37.95, 83.11, 64.46, 74.76, 95.30; Name:Alexander, Rodney
Student ID:76793; Grades: 53.13, 81.02, 83.71, 90.75, 88.92; Name:Baca, Joe
I have to print to the screen the id numbers, the grades and the names
I'm using getline but im having trouble print out the grades
It gets and displays everything except the grades. One of the grades only gets displayed
It should be a while loop, but im just working with the first line for now
ifstream inf;
char fileName[ MAX_STR_LEN ] = "ex.txt";
char testStr[ MAX_STR_LEN ];
int testInt;
double testDouble;
[Code] ....
View 3 Replies
View Related
Feb 26, 2014
I am having some trouble tokenizing some strings in C. I am trying to take in a string dynamically and spit print it to the console tokenized using the spaces as delimiters. I have tried using frets() and scant() as well as playing around with pointer values to no avail.
#include <stdio.h>
#include <unistd.h>
#include<string.h>
#include <stdlib.h>
#define MAX_LINE 80
//function prototypes
void printArgs(int argc, char* args[]);
[Code] .....
View 7 Replies
View Related
Apr 21, 2015
I am trying to copy the stats from the save file "lol.txt" to main. I posted what the contents of the file below, but for some reason the I get for output jiberish and I cannot seem to figure out why.
#define _CRT_SECURE_NO_WARNINGS
#define MAX_NAME 31
#include <stdio.h>
int main(void){
char sName[MAX_NAME];
[Code] .....
View 5 Replies
View Related
Sep 15, 2013
I need a way to count lines in a .dat file using fscanf. I must use a regex to check that the characters in the file are alphanumeric. In essence I need to count the ' ' character. I know fscanf ignores this character. I need to exit if it detects anything other than alphanumeric with the digit that is "problem" along with the line number. My .dat file is:
Code:
howard jim dave
joe
(
Maggie My fileCheck.c is: Code: #include "main.h"
int fileCheck(FILE *fp)
{
int ret_val;
int line_count = 0;
char file[BUFF];
[Code]...
The output I am getting is:
Code:
file opened Digit: ( is not an alphanumeric character on line: 5 Program will exit! File closed As you can see, the character "(" is not on the 5th line but the 3rd. It is the 5th "string."
I also wanted to show the regex I am using.
Code:
#define to_find "^[a-zA-Z0-9]+$"
How this can be accomplished?
View 5 Replies
View Related
Feb 25, 2012
I am trying to use fscanf to obtain a set of 14 or so strings per line, in a line where there are around 80 or so different sets of strings. I only need the first 14 and whenever I call scan f it starts at column 209 as opposed to column 1 where it should. Here's a sample of the code:
FILE *d;
d=fopen("t.dat","rb");
where a, n are all strings.
fscanf(d,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s",&a,&b,&c,..(etc)..,&n);
A sample of the Input file looks like this:
USB270.15385-29.63146 270.153847 -29.631455 2.966699e+03 -9.99 1.300391e+03 -9.99 -9.99 A-A-- 6.787463e+01 -9.99 1.555773e+02 -9.99 -9.99 10100 | ----- ------ ------ ------ | 0.373 13.554 12.928 12.670 AAA | ----- -------- - -------- - -------- - -------- - | --- ---------- - ---------- - --------- - --------- - --------- - ---------- -
View 7 Replies
View Related
Oct 13, 2013
So this program I have to make keeps spitting out an error report when I try and run it. I am using eclipse C kepler.
The file it is supposed to read has the following text;
R1 N001 N003 20
R2 N002 N001 5
R3 N001 0 10
R4 N002 N003 10
R5 N003 N000 5
I1 0 N002 10
View 2 Replies
View Related
Apr 19, 2013
I added this snippet of code to a larger project I use to read some numbers in from a file, but for some reason I'm getting a segmentation fault.
Code:
printf("starting main
");
FILE *cutoffs;
double cut1=0, cut2=0, cut3=0;
printf("trying to open file
The cutoffs.in file looks something like
Code: 3.475 3.875 4.025
I ran the gdb debugger, so I know it is occurring at that fscanf; however, it doesn't give any other details (to be honest I don't have much experience with debuggers :x) ..The values are being put into an array. Before I just had numbers initialized in the array by hand, but need to have 20 different runs of this code with different numbers each time...
View 2 Replies
View Related
Jan 24, 2012
I am trying to make a program that will read in input in the following format:
| ...text... || ...more text... || ...still more text...|
i.e. every bit of "text" that gets read in is bracketed on either side by the "|" character.
The buffer that i read them into can be of a maximum length of 101 (100 characters plus a terminating null character); this is how I am currently reading in the input:
char readString [100 + 1];
while ( fscanf(infile, "|%1000[^|]|", readString) ){
/*... manipulate readString ...*/
}
How might I design this program so that, should any of the text appearing between the "|" characters exceed 100 in length, it exits and returns a warning?
View 4 Replies
View Related
Nov 28, 2014
I am trying to read the name, phone number and address from a file ... Here is the code but it doesn't work and i don't know where is the problem ...
#include <stdio.h>
#include <stdlib.h>
struct PhoneBook{
char name[50];
int phoneNumber;
char address[50];
[Code] ....
And here is the contents of the file:
jack 01014 jgd
Moh 02925 Tyeu
When I run it on dev c++, a message appear saying that the prog has stopped working and no output appears. I want to put the name in user[n].name, the phone number in user[n].phoneNumber and the address in user[n].address
View 1 Replies
View Related
Dec 6, 2013
I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.
Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();
[Code] ....
View 4 Replies
View Related
Dec 26, 2013
I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...
i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....
------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";
[Code] ....
When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.
The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.
I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.
When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..
input = input / BASE; I get C9 where I expected to get 48.
My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?
View 6 Replies
View Related
Jul 10, 2013
I have written the following code to add data to text files which are required to store 3D scan data (I have to calculate the y-coordinate). My code seems to work except that it stops working when I want to create more than ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Code is shown below.
#include <string>
#include <locale>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
[Code] ....
View 1 Replies
View Related
Apr 19, 2013
I want to input data into text file while not deleting the original data in the file and I use something as
ofstream writefile;
writefile.open("example1.txt");
if (writefile.is_open()) {
for(j=0; j<N; j++) {
[Code] ....
But this will delete the original data.
View 3 Replies
View Related
Mar 28, 2015
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.
MY task is to write a program that does the following things:
1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.
2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.
3. Prompt the use for their height (in inches) and their weight.
4. Make the program print the closest BMI.
If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.
5.Loop the program so the user can find more BMI’s.
View 7 Replies
View Related
Apr 20, 2014
Been trying to configure the GridView to display ony 4 rows of data at a time. I thought it wasn't working because I forgot to set AllowPaging to True, but after I did that, I just get the error of
The data source does not support server-side data paging.
Source Error:
Line 66: titlesGridView.DataBind(); // displays query results
Here is my Books.aspx.cs code:
// Fig. 29.11: Books.aspx.cs
// Code-behind file for the password-protected Books page.
using System;
using System.Data.Entity;
using System.Linq;
namespace Bug2Bug.ProtectedContent {
public partial class Books : System.Web.UI.Page {
[Code] ....
Am I missing anything or doing something wrong thats not causing it to page & only display 4 titles at a time?
View 2 Replies
View Related
Apr 26, 2014
I have a situation where I am accessing an ASP.NET Generic Handler to load data using JQuery. But since data loaded from Javascript is not visible to the search engine crawlers, I decided to load data from C# and then cache it for JQuery. My handler contains a lot of logic that I don't want to apply again on code behind. Here is my Handler code:
public void ProcessRequest(HttpContext context) {
JavascriptSerializer jsonSerializer = new JavascriptSerializer();
string jsonString = string.Empty;
context.Request.InputStream.Position = 0;
using (var inputStream = new System.IO.StreamReader(context.Request.InputStream))
[Code] ....
I can call the function : getUserControlMarkup() from C# but I will have to apply some URL based conditions while calling it. The contentType.typeOfContent is actually based on URL parameters.
If possible to send JSON data to this handler then how to do that. I am trying to access the handler like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Common.host + "Handlers/SideContentLoader.ashx?typeOfContent=1&UCArgs=cdata");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
But its giving NullReferenceException in Handler code at line:
ContentType contentType = jsonSerializer.Deserialize<ContentType>(jsonString);
View 1 Replies
View Related
Jan 11, 2014
I'm reading from a file the middle column of data (Volts) where my test file "AP.txt" is opened by my program. Here is a segment of the data:
time Volts dV
49552 -66.20183 -0.01556807
49553 -67.76025 -0.01556495
49554 -69.30704 -0.01533247
49555 -70.81799 -0.0148486
49556 -72.26774 -0.0141133
49557 -73.63226 -0.01315276
49558 -74.89141 -0.01201764
Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.
Here is my program so far:
int main()
{
std::ifstream inFile;
inFile.open("AP.txt");
ofstream results_file ("maxvaluewithinput.txt");
float TimeAtdVMax = 0;
float VoltsAtdVmax = 0;
[Code]...
If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.
View 10 Replies
View Related
Feb 6, 2014
I am wanting to be able to add as many different instances of data, while the user has not stated 'n', but then it only ever writes back to the screen the input for the last set of data. Where as I want to display back to the screen all the data that has been entered.
Code:
#include <iostream>
#include <string>
/*Function Declaration*/
void createItem();
void returnItem();
//Items structure
[code]...
View 6 Replies
View Related
Feb 1, 2015
I'm trying to create a new data type Data declared as int. What comes up to my mind is to create a structure like
Code:
typedef struct Data {
int number;
} Data;
but when I need to use the data I need to go through the structure. Is this a good way to declare a new data type?
View 2 Replies
View Related
Oct 8, 2013
struct receivers
{string fname, lname, team,;
int receptions, yards, TDs, longest,rec20, fumbles, yac, firstdown;
double, averagepergain, averageperrec
}
View 2 Replies
View Related
Jan 30, 2013
I am very very new to C++. A bit of background. I have been writing in excel vba for large number crunching, and the code is now taking quite a while to run. A friend of mine suggested i start writing in C++, so i read up on it. And downloaded Code:Blocks.
My VBA Code is:
Sub arrayss()
Dim NameArray As Variant
Dim datarray As Byte
Dim DirectionArray As Variant
Dim WinArr As Variant
[Code] .....
Ultimately i would like to recode this to C++, but my first and probably silly question is how do i get the data from Excel to use in C++. I was thinking either to put the data in 3 csv files and convert into three Arrays in C++. Or maybe create a library of the data in C++. Ultimately it is speed i am looking for, so before i start recoding i wanted to start with the best way.
The data is like this in excel: (don't know how to create a table)
ABC DCA GFE THE
15 0 1 0 1
30 1 0 1 0
45 1 1 0
00 0 0 1
15 1 1 0
15 1 0 0 1
15 0 1 1 1
30 1 0 0
45 1 1 1
So the headers would be in one array, the 15's, 30's etc would be in another array and the 1's and 0's and Empty ( i need it to record an empty cell) would be in another array...
View 14 Replies
View Related