C++ :: Check If Given 8 Byte Is A Valid Double
May 28, 2014Is there a function in C/C++ that can check if a given 8-byte data block is a valid double value in the valid range?
View 7 RepliesIs there a function in C/C++ that can check if a given 8-byte data block is a valid double value in the valid range?
View 7 RepliesNow I have to write a code which would determine whether an Email address is valid or not.
In my exercise a valid address should look like this : ___@___.___.il (___ for any letters)
E.g. Valid address:
something @ something . something . il Invalid: tami @ jce . ac . uk
(without spaces of course)
Code:
#include <iostream>
#include <string.h>
using namespace std;
int isValid (char s[]) {
int length=strlen(s), ind1=0, ind2=0;
[Code] ....
It doesn't work well. It says both addresses are wrong when the 1st one isn't.
So my program is to check if a certain 9x9 sudoku grid is valid. i have to get the input through command argument. so for example.
./a.out sudoku.txt
So we have make my c program to use FILE I/O open and what not
program behavior must be as follow File does not exist.File contains something other than a sequence of 81 integers (too many, too few, non-int).
One or more of the values is not in the range 1..9 Violation of Sudoku rules (this is the big one!) In case 4, you should report the violation (or any one of the violations if there are multiple -- you do not need to exhaustively enumerate all violations).
For example: Row Violation: entries (2,2) and (2,6) are both equal to 7. (Similarly for column and box violations). All i know is that i need to make a 2d 9 by 9 array
I'm trying to understand why a conversion from a byte array (unsigned char) to a double works when done one way and not antoher.
In the example code I test by hard coding an unsigned char array of the same bytes that the double consists of.
When I copy the bytes to a long long and cast to double the result is not the original double but if I use a struct the bytes can be set and the conversion happens.
Seems to me that both ways should work. I'd just like to know what is going on with the "struct way" that makes the conversion correct. I see in debugger that the bytes in memory are the same for piAsLong and u.bytes.
My compiler is VS 2012 and a long long and double are both 8 bytes (tested with sizeof). This is learning activity only.
Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
union {
double d;
[code]....
I was asked by a friend about validity of following function prototypes,
void func1(int = 0, int*);
void func2(int = 1, int& = 2);
void func3(int*, int& = 3);
void func4(int& = 4, int* = 0);
void func5(int& = 0, int = 1);
void func6(int = 5, int& = 6, int* = 0);
I think the only prototype that is invalid is func1 because it does not have default parameter on the far right.
I want to know if it's valid to use and/or when using the conditional operator.
Example:
value = textBox1.Text;
decimal? qty = (value.Equals("0") || value.Equals("0.0")) ? null : (decimal?)decimal.Parse(value);
The following code writes to a file on either local disk to a remote disk (commented out code) on Windows 7 platform.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream outfile;
[Code].....
The documentation does not specify what is a valid filename (path and filename). For example, will the "\server emp" path work on all operating systems to access a samba share? Does the constructor accept forward and backward slashes as folder separator on all operating systems?
How can I write my simple program so if the user enters an invalid number, The program won’t exit? I know I am supposed to use a if (cin) or if (!cin),
But I don’t know where in the program or how I should use it. Right now my Program looks kind of like this:
If (number > 1 && number < 1001)
Go through some function loops
Else
Cout << “invalid number”;
I need to write it so when the user enters an invalid number, the program would Keep asking for the right number until it's given.
Is this a good way of writing this program?I wanted to start fresh with my new code though and a better title.Basically, I took what I learned from my questions in that thread and managed to build a list of musical notes( octaves, frequencies, sharp symbols, basically everything ).
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX_NOTES 88 /* 88 keys on a standard piano */
[code]...
I already know the frequencies are correct( they are rounded, but they should be close enough to the value ), but I wasn't so sure about the note labels. Obviously though, I'm not done with this program and I will be adding most of the functions Anduril suggested to take a text file and convert it into music. I just wanted to make sure I had everything correct before moving on. I probably didn't do the GetNextOctave() and GetNextNote() functions very efficiently so need suggestions on those functions also.
I have this piece of code in parts of my path finding algorithm
for( int head; head < q.size(); ++ head ){
walk& w = q[head];
// do manything with w
if( some_condition ) q.push_back( walk( w.x + 1, w.y, head ) );
}
However I notice that sometimes w is cannot be dereferenced. It can but it throws junk number at me. Perhaps the vector is changing it size and move the whole array to a different location. Is there anyway to make sure that w is always valid ?
I just want to use w because of shorter typing and cleaner look not because of performance. I also refrain from using macro.
Entering valid user input?
How can I write my simple program so if the user enters an invalid number, The program won’t exit? I know I am supposed to use a if (cin) or if (!cin), But I don’t know where in the program or how I should use it. Right now my Program looks kind of like this:
If (number > 1 && number < 1001)
Go through some function loops
Else
Cout << “invalid number”;
I need to write it so when the user enters an invalid number, the program Would Keep asking for the right number until it's given.
#define PROJECT_ID ram
#define QUOTES(FILENAME) #FILENAME
#define DATA_VAR_FILENAME(PROJECT_ID) QUOTES(../##PROJECT_ID##_data_var.h)
#define DATA_VAR_FILE(PROJECT_ID) DATA_VAR_FILENAME(PROJECT_ID)
#define CUST_DATA_VAR_FILENAME DATA_VAR_FILE(PROJECT_ID)
When I tried to include CUST_DATA_VAR_FILENAME like below
#include CUST_DATA_VAR_FILENAME
Will get below error
error: pasting "/" and "ram" does not give a valid preprocessing token
Why does the following line of code generate error as " pasting / and / doesn't generate a valid reprocessing token"?
Code:
#define comment /##/
int main() {
comment printf("hello");
return 0;
}
if I include iostream twice in my project why is that valid? Wouldn't the linker see that there are two definitions of it and report a error, but it works?
By project I mean in multiple translation units.
I have the below code, the first rich text box works fine but on the second i get the error
An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Additional information: File format is not valid.
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Rtf = reader["Change_Description"] as string;
Change_Description = rtBox.Text;
System.Windows.Forms.RichTextBox rtBox2 = new System.Windows.Forms.RichTextBox();
rtBox2.Rtf = reader["Change_Justification"] as string;
Change_Justification = rtBox2.Text;
C# type setting a char? I have tried setting as characters, as integers but nothing seems to work?
last try: char mchar = 'X'; // Character literal
I am getting this error whenever I leave my drop down lists blank: "String was not recognized as a valid DateTime". My code is below:
aspx:
asp:DropDownList ID="cboDay" runat="server" Width="55px" Height="32px" AppendDataBoundItems="true">
<asp:ListItem></asp:ListItem></asp:DropDownList >
<asp:DropDownList ID="cboMonth" runat="server" Width="80px" Height="30px" AppendDataBoundItems="true">
[Code]....
I just wonder whether 0xFFFF is a valid Unicode character.
When I using the following code:
CStringW strTempW;
CString strTemp1;
INT_PTR nLen;
strTempW.Format(L"%c", 0xFFFF);
nLen = strTempW.GetLength();
strTemp1 += strTempW;
nLen = strTemp1.GetLength();
After executing the first codeline strTempW.Format(L"%c", 0xFFFF), I will get strTempW of length 1, but cannot see it first character in Visual Studio watch window.
After executing the codelilne strTemp1 += strTempW, I will get strTemp1 of length 0.
Whether 0xFFFF is taken as a valid Unicode or not?
I have to write a code which would determine either a URL address is correct or not.
Now, a valid address should look like: "www.something.something.uk".
It has to have 3 dots, 3 w-s in the beginning, and it must end with "uk".
E.g.
Valid addresses:
1. www.jce.ac.uk
2. www.tr2213.oi34.uk
Invalid addresses:
1. www2.jce.ac.uk
2. òæøéàìé - îëììä à÷ãîéú ìäðãñä éøåùìéí - ìéîåãé äðãñä ìúåàø øàùåï
3. www.something.uk
Just to be clear, this criteria mentioned above is not real, just homework
Code:
#include <iostream>
#include <string.h>
using namespace std;
int isValid (char s[])
{
int dots=0;
[Code] ......
It tells me both strings are incorrect but the first 1 is.
What is the most efficient way to read a bit at a particular position in a byte?
View 13 Replies View RelatedRight now im creating a program that use xbox inputs and then send out keyboard functions using sendInput();
It works fine, but now im creating a system wich lets the user of the program change the settings in a textfile. Wich will then change what the controllers bindings are.
example, if settings.txt says: Y=button(0xIE)
i want the program to know that when xbox button Y is pressed, execute a sendInput function to the Key: A (0xIE).
The problem is that the virtual keycode (0xIE) i take from the settings.txt is stored as a string (lets say it is stored in string Y_event)and input.ki.wScan has to be of type BYTE. i made a function wich changes string into int. (because input.ki.wScan seems to be fine getting a int?)
int stringToInt(string insert) {
char back[20];
for(unsigned int e=0;e < insert.length();e++) {
back[e]=insert[e];
} return atoi(back);
}
but when i run the code nothing happend...
In the code i have a function wich executes the keypress: void pressbutton(int key, int time)
when i send in the converted string it doesn't work but when i send in: (0xIE) it works.
pressButton(stringToInt(Y_Event),50) // doesn't work
pressButton(0xIE,50) // works
focus on the last part that i wrote.
What is the most efficient way to read a bit at a particular position in a byte?
View 3 Replies View RelatedI'm trying to get the current time for a game and print that to the games chat window. I'm already injected into the process do I don't think I need ReadProcessMemory.
The value i'm trying to read is the game hours 1-12.
//doesn't work
byte time_hour_get ( void )
{
return *( byte *)0x00B70153; //the address to the memory containing the
}
addMessageToChatWindow((char*)time_hour_get); -> when I call this function it looks like s , . I want it to return the integer value like cheat engine. I used byte when scanning for this address
Basically it has to do with the byte ordering in a binary buffer vs the typing of a variable used to hold it.
To give you an example, if I have a buffer (say of indefinite length), and a ptr "ptr" pointing to a byte in the buffer (say, C0), such that if I open the buffer in a binary viewer it reads like this: Code: C0 DD FE 1F Such that this is true:
Code:
/*ptr is uint8_t*/
*ptr == 0xC0
Then I do this:
Code:
uint16_t var;
var = *(ptr+1);
I would expect the result to be:
Code: DD FE /*56830*/
Though if I print that out with:
Code:
printf("%u
", var);
It'll print:
Code: 65245 /*(FE DD)*/
Now obviously it's byte swapped, but what is causing that? I'm assuming if I just stream that out to a file byte by byte it'll be fine, so it's something with the 16 bit data type (also have seen this issue with a 32 bit data type, where all 4 are in reverse order). Is there any way to 'fix' it except bit shifts & masks?
Are locations in the RAM addressed per word or per byte? I am using a 32 bit machine, so I think that it means that on my PC a word would be 4 bytes.
View 11 Replies View RelatedI basically want to create a save editor application that will enable people to alter various values in the save by clicking on releveant buttons and then also for the editor to auto update the checksum when changes are done.
The save file is in hex so from what I can gather I would need to create a button to open the file using 'open file dialogue' and then read the file into a byte array so that the values can be called at any time when a particular butto is pressed and the application will then seek to the point in the file to make the required changes.