C++ :: Using Bitmask Operators - String Bin To Char
Mar 3, 2013
So this is the code I have so far which puts a bitmask seperator base on what I choose. My problem is when Im trying to do them in this manner.
1. 0 to 31, with minimum width set to 8, and separating between every 4 digits.
2. 2^0 to 2^16, with minimum width set to 17, separating between every 8 digits.
3. (2^0-1) to (2^16-1) with minimum width set to 16, and no seperation between digits.
I try doing number 2 called "String multyplyByTwo" but seems to be getting errors.
#include<iostream>
#include<string>
using namespace std;
string binToChar( const int n, unsigned minWidth = 8, unsigned sepMask = 0x11111110 ) {
I have a calculator with buttons, and when I click the numbers or operators, it goes to a string array. So;
Press 3 Press + Press 2 Press =
and my array is str[0]='3' str[1]=.... so on...
And also I have a C code which calculates the string you entered with some algorhytms and gives a double value as a result. So the question is;
How can I send my STR array in C# to my C program? I mean I want to use my C program as a source code. and How to return that double value to my C# program?
For now, I don't want to change my C codes into C# codes. I want it to keep as is. Just use it as a source code. Is that possible?
I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
Code:
#include <iostream> #include <conio.h> using namespace std; int main ()
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox. char selectedValue[256]; memset(selectedValue, NULL, 256); SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue); // Convert to string. string val(selectedValue);
Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.
This sends the buffer to a LIN modem. My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?
I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.
I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).
I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.
.. #include <string> .. char* decryptPwd(char hash[64]); main () { string mypwd; string newmypwd; if (decryptPwd(mypwd)==newmypwd)
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);
I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.
the function looks like this:
Code: int printUser(){ printf("Following patients have been recorded in this session: "); struct database patient1; struct database patient2; struct database patient3;
[Code]...
the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):
I want do delete all occurrences of a char in a given string, but I really don't see my error in the code. Here is how I did it:
Code:
char *input = "example_string"; int len = strlen(input); char *new_line[len]; char bad = 'e'; //the one to delete int i; int j = 0;
[Code]...
I get segmentation or bus errors.. And I also don#t understand the warning I get. new_line is an array of chars, and I am trying to assign to it a certain char.
I'm extremely rusty at C but is this the best way to store an input string into a char*?
Code: int length = 100; //initial size Code: char * name = malloc(length * sizeof(char)); //allocate mem for 100 chars int count = 0; //to keep track of how many chars have been used char c; // to store the current char
while((c = getchar()) != ' '){ //keep reading until a newline if(count >= length)
name = realloc(name, (length += 10) * sizeof(char)); //add room for 10 more chars name[count++] = c }
So I have an array of char called s.This array has many words inside, each one separated by ''.The words are sorted by length (from bigger to smaller).I have have a char matrix with random things inside (it was not initialized) caled mat.I want to copy the first word from the array s to the matrix mat.
Code:
int nlin, ncol; /*number of lines and collumns.*/ int c,l,a,q; char mat [1000][1000]; char s[1000]; }
[code]....
I can't see where this is wrong, but, when i test it, it clearly is not right. for example, if the input is 3 lines and 3 columns for the matrix and the word is crate, the output is :
I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.
Example:
receives 2 3 ABC DEF 2 1 1 1 2
returns
AB
this is how i tried to solve this problem:
Code: #include #define MAX 1000 int main() { int nlin, ncol; char mat[MAX][MAX]; int x[MAX], y[MAX]; int ncoords; int l, c, n;
/* receiving variables and storing matrix.*/
[Code] .....
For some reason that i can't seem to find, this solution is not right.