C :: Reading In A File Of Chars Until EOF

Apr 13, 2013

I'm working on a homework project, and it requires me to read in a file of chars into an array, and then do stuff with that array.

Anyways, I have the first part written, where I'm just trying to read in my data.txt file, and I thought I had it written well. It compiles, but then it seg faults, and I'm not sure why. I used calloc for the array, but maybe I misused it? Or is it in my EOF statement? I'm still not sure if that's coded correctly. I need to get past this so I can start testing the other parts of my code.

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

int main(int argc, char* argv[] ) {
/* Local Declarations*/
int i;
int *ptr;
char tempc;

[Code] .....

View 1 Replies


ADVERTISEMENT

C/C++ :: Loop Runs Twice When Reading Chars To Array From File

Nov 26, 2014

I am trying to write a function to save the state of a tic tac toe game. It seems to be working well except the loop to read the chars in from a .txt file is running 18 times instead of 9 and thus overwriting the array with blank boxes. The code below is the part of the function I am having an issue with. Counter is being increased every time the second for loop runs which should be 9 times. However, it is apparently running 18 times with the first 9 runs filling newBoard correctly and the second 9 times overwriting it with boxes. how to fix it?

ifstream inputFile("file.txt");
char newBoard[3][3];
char a;
int counter = 0;
while(counter<=9) {
for(int r = 0; r<3; r++)

[code]...

View 2 Replies View Related

C :: Adding Chars From File To Array

Jan 29, 2014

lets say we have a txt that contains this

| | | | |*| |
| | | |*| | |

and that symbolizes a 2x6 char array and we want to take only the symbols inside the || and place them in a 2x6 char array. how do we do that?

View 1 Replies View Related

C++ :: Looking For Chars In String

May 20, 2013

I'm looking for a algorithm to search portions of string that have the same caracter. The only possible values are: a,n and g

Char index: 0 1 2 3 4 5 6 7 8 9 RESULT
------------------------------------------
Example 1: a g g g a a 0,4
Example 2: g g g a n n a 0,3
Example 3: a g g g g g g a 0,7
Example 4: g g g g g g g 0,6
Example 5: g g a a g a a a g 0,2,3,5,7,8

View 4 Replies View Related

C :: Swap Chars Using Getchar

Sep 23, 2014

This is for homework . Must use only getchar and putchar

Code:

int main(void) {
int pch; //first
int ch; //second

[Code]....

And it works , but i need to hit ENTER two times when i have 3,5,7... chars to print result.

View 6 Replies View Related

C++ :: Convert Chars To UTF-8 Hex Strings

Sep 27, 2013

I am trying to convert some chars to UTF-8 strings...

Example:

std::string gethex(char c) {
/* EXAMPLE
if (c == 'é')
return "%c3%a9";
I need a function that converts chars like "á, é, í, ã" to UTF-8 hexadecimal strings...
*/
}

[Code] .....

[URL] .... does it. Choose UTF-8, type some character and click 'Url Encode'.

View 14 Replies View Related

C++ :: Comparing Chars In A While Statement

Jul 1, 2014

I am trying to do this but it can never seem to work.

#include <iostream>
using namespace std;
int main () {
char charOne;
cin.get(charOne);
cin.ignore(1000, '

[Code] .....

Basically i want to keep looping until i enter an a or A (also does this apply to if statements as well?)

View 6 Replies View Related

C/C++ :: Put Special Chars In A Message

Apr 10, 2014

I'm trying to put in my messages, in my program, some special chars but when i try something like the following code, i get the output below.

#include <stdio.h>
int main( ) {
printf("Trying this char: %c", 160);
printf("Trying this char: %c", 163);
return 0;
}

Output:
Trying this char: �
Trying this char: �

How can i put those special chars? I would like to use: é, ú, ç, à, Ú, À, ...

View 14 Replies View Related

C/C++ :: Printing Out Unicode Hex As Chars

Feb 10, 2014

I'm writing a school assignment that writes/reads user input into and out of a binary file.

I've gotten the write part to work, but now I need to be able to read that file back in and display it as a string.

I think I should be using fread() and read my file into an array of int's right? But when I try printing out that array I get a whole bunch of numbers that don't match the hex code in my file.

How do I read in a binary file and print it out as a string?

View 4 Replies View Related

C# :: Reverse Chars Of String

Aug 7, 2014

I have a problem with my code. I just have to reverse the chars of a string, but it adds a /n that I can't delete.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ch05Ex05._5 {

[Code] ....

View 5 Replies View Related

C++ :: Print Chars As Keys Are Hit?

Mar 31, 2012

I found this method

Code:
TCHAR win_getch()

(below) on a website which is used for printing the characters as the keys on keyboard are hit i-e without hitting the ENTER key. This method is used in a while loop like this

Code:
while ((c = win_getch()) != 13)
{}

I wanted to know why is the character compared to

Code:
13
i-e
Code:
if((c = win_getch()) != 13) then do something

Code:
/**
* This function will simulate the getch() function from conio.h.
* Note that this does not work for special keys like F1-F12, arrow keys,
* even the ESC key does not seem to work with this function.
* @return TCHAR read from input buffer.
*/
TCHAR win_getch() {
DWORD mode;
TCHAR theChar = 0;

[code]....

View 2 Replies View Related

C :: Converting Random Numbers Into Chars?

Apr 3, 2013

I am having difficulty completing 7th last line below I marked the line with an arrow.

Code:
int main(void) {
int MaxNum, /*number of random nos to generate */
i, /*index */
value,

[Code].....

View 4 Replies View Related

C :: How To Convert From Array Of Chars To Strings

Jan 13, 2014

As a part of a program I am supposed to write, I would like to receive a string from the user (for example: "Hi my name is Joe").

obviously, the string is inserted to an array of chars (arr[0]='H', arr[1]='i', arr[2]=' ',... and so on).

What I would like to do, is to put each word separately in each array cell (for example arr[0]='Hi', arr[1]="my"..., and so on). How can I do this? (I can not use any functions, unless I write them myself).

View 8 Replies View Related

C++ :: Remove Non-Displayable ASCII Chars

Jan 7, 2014

How to give input with text for this function.i already create function for this but i dn't know give input as non ASCII value(0-32) that Cobain with string or simple text.

View 1 Replies View Related

C++ :: If Multiple Same Chars Found Then Drop One

Nov 20, 2013

For some reason my code is not couting right. My function is supposed to decipher some code that if it has multiple same chars then it drops one. Example aabbyfkk --------> abyfk. But it couts abyffkk . For some reason it is not getting rid of the extra f and k chars.

string decrypt (string encrypted) {
string deleted, tmp;
int i, pos, n, j=0, z;
tmp=encrypted;

[Code] ....

View 3 Replies View Related

C/C++ :: Sort Out Input - Getting Rid Of Chars And Only Using Numbers

Apr 2, 2014

I was supposed to sort out an input, getting rid of chars and only using the numbers. So 5a6g7we87hj9 would become 567879. I might be wrong in some way, but I used

if (scanf("%d", &n) {
printf(" %d", n);
}
else {
printf("Error);
}

and it sorted correctly.

View 1 Replies View Related

Visual C++ :: Best Way To Read Array Of Chars

Jan 16, 2014

I am receiving a max of 50000 bytes from a socket.

char packet1[50000];
recv(Socket, (char*)&packet1, 50000, 0);

What is the best way to read those bytes? Let's say I need to see if bytes 14-15 and byte 16-17 equal each other.

Only thing I can think of is to create a buffer array of 2 chars, and feed the bytes into those and compare them. Is that right?

View 5 Replies View Related

C :: Reading From A File And Skipping Lines To Find String In File

Nov 26, 2013

Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.

The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.

The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.

The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)

The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.

The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.

The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.

The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:

If a patron buys a ticket at the door, a command will be on a line by itself:

BUY TICKET k

where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.

Code:

#include <stdio.h> #include <stdlib.h>
#include <string.h>
#define N 1000

[Code].....

View 4 Replies View Related

C :: How To Account For Different Number Of Chars In Array Of Names

Dec 9, 2013

I am trying to make a for loop that will print out chars in an array while using a #define before main. My problem is that each name has a different amount of chars in it. How do you account for that when you are trying to define a size? For example, I am playing around with the numbers and I just put 7 in for size:

Code:
#include <stdio.h>
#define sizeOf 7
//char personName( char * name[] );
char printName ( char * name[]);

[Code] .....

View 8 Replies View Related

C :: Replacing Individual Chars In A String Array?

Nov 16, 2013

I'm trying to right the function that puts the correct letters in the right positons being reported from my previous compareletter function for my game of hang man and its not updating the word in progress array. Here's my compare letter function that's working correctly:

Code: //function that returns the index of the letter that the user has guessed or Code: //-1 if the letter isn't in the word
int CompareLetter(char array[], char guess, int numLetters)
{
int i;

[Code....

However, this isn't changing any of the position of the asterisks in the word in progress array positions 0-3.

View 7 Replies View Related

C :: Pointer Size Increase - How Many Chars It Can Store

Dec 14, 2013

That code should make the size of the pointer (how many chars it can store) bigger but when i run it it show always 3 char positions while it should show N*M.

Code:
#include <stdio.h>#include <stdlib.h>
int main(void) {
int M, N, P, i;
scanf ("%d %d", &M, &N);
P = M * N;
char *c = malloc(P * sizeof(char));

[Code] ....

View 7 Replies View Related

C++ :: Write Program That Reads Group Of Chars?

Nov 28, 2014

Write a program that reads a group of chars till $. Then, compute # of vowels, # of digits, # of word and # of special chars. Your program should display all required results.

So in what way should I do it? Loop, array, ...?

View 13 Replies View Related

C/C++ :: Convert The Functions To Deal With Integers Instead Of Chars

Mar 29, 2014

current functions are:

char *createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(char *environment, int width, int height);

need to be:

int* createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(int* environment, int width, int height);

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

[Code]....

View 1 Replies View Related

Visual C++ :: Detecting Garbage Chars In CString

Feb 1, 2013

How do I detect garbage chars in a CString. Actually I'm reading some data from COM port. In some certain condition it will give some garbage as a version no. Now I need to show _T("N/A") in case of there is any garbage.

My solution is to check for a Valid char or integer. If found its correct else Garbage.

View 11 Replies View Related

C/C++ :: Program To Find Min / Max Values Of Two Ints / Doubles And Chars

Jan 31, 2015

I'm supposed to create a program that will find the min/max values of two ints, doubles, and chars, It's not completely done but here's what I have so far.

It's giving me an Error 1 error LNK2019: unresolved external symbol "public: __thiscall MinMax<int>::MinMax<int>(int,int)" (??0?$MinMax@H@@QAE@HH@Z) referenced in function _mainC:UsersDerickDesktopCiss243Week3 Assignment2Week3 Assignment2Main.objWeek3 Assignment2

Header file
#ifndef MINMAX_H
#define MINMAX_H
#include <iostream>
using namespace std;
template <class T>
class MinMax

[Code] ....

I don't know why the site is adding in extra bits of code like /> in certain areas, it's not there when I paste it in and it's not in my code ....

View 5 Replies View Related

C/C++ :: Printing Table Of ASCII Chars - Cannot Initialize Variable

Apr 9, 2014

I'm trying to write a program which prints a table of ASCII chars, I'm not really done with my thoughts on it but I already
ran into the following error:

Error: cannot initialize a variable of type 'char' with an rvalue of type 'char (*)[16]'

Here's my code so far:

# include <iostream>
using namespace std;
int main() {
char asciiTable = new char[8][16];
int nextSign = 0;

[Code] .....

View 4 Replies View Related







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