C++ :: Simply Converting Character Array To A Short Int

Feb 14, 2013

Any function of simply converting character array to a short int?For example. char array[4]={'0','2','f','f'}; to short int 767?

View 3 Replies


ADVERTISEMENT

C++ :: Modify Contents Of 1D Character Array - Converting To Upper Case

Feb 10, 2015

I am unsure how to write a function which modifies the content of the 1D character array and puts all of the letter it contains into uppercase. the following are the letters which i am trying to convert.

char text[MAX+1] = {'T', 'e', 's', 't', 'e', 'r', EOT};

The output to this should look like T E S T E R EOT

View 2 Replies View Related

C :: How To Simply Input CSV File Into Universal Variable 2D Array

Mar 6, 2015

I am working in an assignment and part of this assignment is to input a CSV file with floats such as this:

8.5, 10.5, 90.5
49.5, 99 ,97
88, 70, 100
78, 2, 10

into an universal variable array.I just want to figure out a way to simply input the CSV file into a 2D variable array.The values in the array will be later use in functions that I'm trying to figure out but I can't do that until I store these values in the array. I think is just a matter of figuring out how to tell fscanf to ommit spaces and commas, but I don't know how. This is what I have done

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float grades[1001][101];
int main(int argc, char* argv[]){

[Code] ....

The output is this

Assignment 1 of student 1 = 8.5 Assignment 2 of student 1 = 10.5 Assignment 3 of student 1 = 0.0 Assignment 1 of student 2 = 90.5

I think I'm close to solve it but something is missing the output should look like this

Assignment 1 of student 1 = 8.5 Assignment 2 of student 1 = 10.5 Assignment 3 of student 1 = 90.5 Assignment 1 of student 2 = 49.5

View 1 Replies View Related

C++ :: Returning Short Int Array In A Function

Feb 14, 2014

I'm trying to return a short int in a function..This is my function signature :

short int* StartRecord(int seconds)
this is my array :
short int waveIn[NUMPTS];

I'm trying to get the data into an array :

short int arr [] = StartRecord(3);

getting this error: Error2error C2440: 'initializing' : cannot convert from 'short *' to 'short []'

View 1 Replies View Related

C++ :: Convert 2-byte Array To Short Int?

Nov 18, 2012

I'm having trouble reading a block of bytes into a vector of short ints. My code is as follows:

Code:
FileStream.seekg(2821);
vector<short> g_Data;
int iter = 0;
g_Data.reserve(maxNumOfInts);

[Code] ....

The relevant block of data starts at offset 2821 in the file. Every two bytes are a signed short integer. What's odd is that it's giving me the correct results only part of the time. At offset 1052421 and 1052422 there are two bytes 40 and 1F that are correctly read in as 8000, but at offset 1052415 and 1052416 bytes 88 and 13 are read in as -120 instead of 5000.

I don't see anything wrong with my code, though, unless I'm misunderstanding completely how to convert an array of two bytes into a single float. Is my method correct? Better still, is there some way to just convert en mass an array of bytes into a vector of signed short ints?

View 5 Replies View Related

C++ :: Converting Reference Address To Character String

Jun 15, 2014

I'm wanting to convert the reference address held by a pointer into a character string, combine the hexes into a single unsigned long int(using bitwise operators )so I can use the 32bits in conjunction with a separate algorithm to develop a more efficient, but less 'random', number, or should I say bit, generator that I'll be using in a Neural Network, with Genetic Algorithms used to modify the weights.

View 5 Replies View Related

C :: Assignment Of Element Of 2D Character Array To 1D Character Array

Jul 4, 2014

Can we do this :

Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];

View 3 Replies View Related

C :: How To Use Accelerometer To Simply Light Up LED At Certain Angle

Mar 17, 2014

I want to use an accelerometer to simply light up an LED at a certain angle. I want to use all three axis each corresponding to a different LED.

I am however getting no change in the LEDs. My code is below.

Code:

#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30 // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L

[Code]...

View 6 Replies View Related

C++ :: Count Numbers Of Words In A Sentence Simply By Counting Spaces

Jan 22, 2014

I wrote a code that counts numbers of words in a sentence, simply by counting spaces... but instead of showing a true number it shows a wrong number.

#include <iostream.h>
#include <conio.h>
int check(char eh[10000]) {
int he=0;
for (int i=0; i<=10000 ;i++) {

[Code] ....

View 8 Replies View Related

C++ :: Difference Between Int And Short Int

Aug 19, 2014

size of int is 2 bytes and of short int is also 2 bytes.The range of values for int and short int are the same.

Then why int and short int are used? only int or short int is enough ....

View 4 Replies View Related

C/C++ :: How To Set Each Bit If The Variable Is Short

Jan 3, 2013

i am using the below logic. but it gives me error when i am setting the bit_position 15 or 16. i suspect, the problem with the integer range.

short bit_map, bit_position  
bit_map = bit_map | ( 1 << bit_position )

View 2 Replies View Related

C++ :: How To Set Certain Bits Of Unsigned Short

Aug 8, 2013

I have a double variable and depending on certain conditions I need to set certain bits of an unsigned short Variable. For example, if double var is odd I need to set the 15th bit of the unsigned short variable.

View 4 Replies View Related

C/C++ :: How To Null Terminate Unsigned Short

Jul 23, 2014

I've stored a binary pattern in what is interpreted as an unsigned short.

unsigned short byte_one = 128;

I've done some bitwise manipulation and want to store it back into an array, however, it needs to be null-terminated.

buf[1] = byte_one;

How do I null-terminate this?

View 3 Replies View Related

C++ :: Printf With Signed Short / Byte

Jul 17, 2012

I am using print/sprintf with a "%i" format string. Works fine if the input is indeed a 32bit integer. But how can i put in 8/16 bit (ie short & byte) 'integers'? If i just throw them in, they are always taken as unsigned, as the topmost bit/s is/are casted to zero... [URL] ....

View 3 Replies View Related

C :: Store Character Array In Reverse Order Then Display Reversed Array

Jun 14, 2013

The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?

Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^

[Code] ....

Is it just my compiler?

View 5 Replies View Related

C/C++ :: Polymorphism Is Stopping Short Of Desired Class

Mar 2, 2014

I've been working on this project which inserts data for different types of books lately, and I'm trying to utilize inheritance and polymorphism. The issue I've been having is after I create an object with my MediaFactory, I go to insert data into that type of object, but it won't reach the correct child class. The parent class in this case is MediaData. The class I'm trying to reach is Childrens, and the class that falls in between is called Book. The function I'm calling to insert the information is setData(ifstream&). This function simply places the information from a txt file into an object with the insertion operator.

Right now the program runs into the setData function of Book instead of Childrens. I need Childrens so I can enter all the required attributes (title,author,year). The call to this function is in MediaManager through the function called buildMedia, and my test is running into the case if (type == 'Y'). From there a pointer of type MediaData is created and pointed to a new object returned of type Childrens. I'm using my debugger in Xcode which does show that the correct object type (Childrens) was created.

I've tried a couple things so far. First I created another function called getData. From there I passed in *media and infile (txt input file) into that function, which then passed it right into setData with a pointer to the object and infile in the parameter. That didn't work, so I also tried going back into Childrens and removing MediaData from all my virtual functions and replacing it with Book. I got the same result when that happened; It morphed into Book class instead.

I have a portion of my UML as a reference. Childrens is a Book; Book is a MediaData. I also included all code for MediaManager, MediaHash, MediaFactory, MediaData, Book, and Childrens.

I did not include the operator overloads in the .cpp files to eliminate some redundancy.

//-----------------------------------------------------------------------------
// MediaManager.h
// Manager class for MediaData type objects
//-----------------------------------------------------------------------------

#ifndef MediaManager_H
#define MediaManager_H
#include "MediaHash.h"
#include "MediaFactory.h"
#include "MediaData.h"
using namespace std;
class MediaManager {

[Code] ....

View 3 Replies View Related

C/C++ :: Testing Character Array Against Array Of Characters?

Apr 16, 2014

I am currently having an issue with validating user input for a state abbreviation. I have an array where a list of abbreviations is stored to use as a comparison for whatever the user inputs. I have been able to get the list loaded properly but whenever i go to compare, it always comes back as true even if it isn't. Here is some relevant code:

static char stateTable[STATE_TABLE_SIZE][STATE_SIZE];
int main() {
char buffer[40], *testCustName[40], testState[5], testCode;
buffer[0] = '';
int quit = 0;
int p = 0;

[code].....

View 6 Replies View Related

C++ :: Converting From Class Array To Int

Mar 24, 2014

Version 1 (works fine)

Creating array in main and then calling a sorting function from sorting class.

In main:

const size_t SIZE = 100;
int *array = new int [SIZE];
//fill array with ints, not shown here
quickSort(array, SIZE); //calling the sorting function in the sorting class

In the sorting class, quickSort is declared as such:

void quickSort(int arr[], int num);

Everything works great.

Version 2 (issues)

Instead of creating the array in main, I have set up a class for the array, MyArrayClass, where I create an object containing the array of ints. So far so good. The issues come when I write a member function to call quickSort. Even though my MyArrayClass object contains an array of ints, the code calling for quickSort() won't compile as the data type isn't ints but MyArrayClass (which in turn holds ints though). The compiler (using VS 2013 btw) complains that quickSort can’t convert the first argument from 'const MyArrayClass' to 'int[]'.

How do I cast my class object array of ints as an int[] in order to be able to call the quickSort function? Or should I solve this issue in some other way? I tried altering the sorting function to accept the object as it is, but that only created an avalanche of new errors, so thinking that converting/casting the object array --> int[] might be easier...

View 6 Replies View Related

C++ :: Converting 1D Array To 2D Matrix?

Jan 12, 2015

Q.Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

Ans.

#include<iostream>
using namespace std;
int two_print(int x, int one[999]) {
int two[999][999], q=x, z=x;
for(int k=0; k<x; k++) {
q--;

[code].....

View 2 Replies View Related

C/C++ :: Converting 1D String Array To 2D

Mar 27, 2015

I am trying to convert a 1d string array to a 2d but i couldnt do it. Heres my code so far,

for(i=0;str2d[i][j]='';i++)
{
for(j=0;str2d[i][j]=' ';j++)
{
str2d[i][j] = str1d[k];
k++;
}
}

str1d is a paragraph btw.I tried using NULL instead of '' but didnt work either.

View 5 Replies View Related

C++ :: Converting String To Char Array

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.

Code:

//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 1 Replies View Related

C :: Converting Function Data To Array

Apr 4, 2013

How can I change this function so it stores each of the even integers into an array of integers?

Code:
void sumIntegers ()
{
int num = 0;
int i = 0;

[Code]....

View 1 Replies View Related

C++ :: Converting String To Integer Array

Apr 17, 2014

For Example, it the entered string is: 0324152397 I want it to get stored in an array like-[0] [3] ...[7]. Secondly the string entered may be of any length that is defined only at run time. So, I also need to calculate string length. How could I do that.

View 2 Replies View Related

C++ :: Converting String Into Double Array

May 18, 2014

I am having a lot of trouble extracting values from a string into a double array.

I have a string that looks something like this: "asdf 1.320 1 234.43 5.00000 3"

All I want to do is extract the doubles and store them in an array of doubles.

View 8 Replies View Related

C++ :: Typecasting Char Array To Int (Not Converting)

Jun 1, 2014

I am looking for the correct syntax to typecast a character array as an int. So I would be able to do something like this:

char ch[4];
//...Read characters from file into ch or something, etc...
int i = ( int ) &ch;

or

char ch[4];
//...Read characters from file into ch or something, etc...
int i;
strncpy ( ( char* ) &i, ch, 4 )

I want all the 4 characters ( or bytes ) of ch to be classed as an int. So we are taking the 4 bytes of the character array and placing them in 4 bytes of the integer? How would i go about this?

View 2 Replies View Related

C/C++ :: Converting 2D Array Code To Malloc

Mar 2, 2015

I made a program that adds two matrices and displays their sum with a max dimension of 100.

/* This program asks the user for 2 matrices called A and B, as integers,
and displays their sum, C. The max dimension of each matrix is 100. */

#include <stdio.h>
// Construct function
void construct() {
int m, n, i, j; // Variables
int first[100][100], second[100][100], sum[100][100]; // Matrices variables

[Code] ....

Now I need to change it so there is no max size for each matrix. The arrays will be larger than 100x100 so I need to use malloc to create my arrays. So I cant use int A[rows][cols]. This is what I did to covert arrays to malloc. It compiles but it crashes after I entered all the integers.

/* This program asks the user for 2 matrices called A and B, as integers,
and displays their sum, C. The max dimension of each matrix is 100. */

#include <stdio.h>
#include <stdlib.h>
// Construct function
void construct() {
int m, n, i, j; // Variables
int *first = NULL;

[Code] .....

View 8 Replies View Related







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