C :: If Fread Returns Char Array Less Than Eight Bytes?
Mar 1, 2013I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
View 8 RepliesI do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
View 8 RepliesI've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
I need fastest method to reverse order of bytes in my char array.
For example i have:
unsigned char buf[8];
// consider data stored in buf is 88 77 66 55 44 33 22 11
// how to reverse it to: 11 22 33 44 55 66 77 88
// currently i can do it by equal assignment , i make another buf like:
unsigned char buf_ok[8];
[Code] ....
// This does reverse the bytes as i want but its very slow , i am looking for fast method ..
#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;
[Code] .....
I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.
I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
Code:
//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;
[Code].....
I have used the following code to write and read wchar_t bytes from a disk file:
Code:
int WriteBytesW(wchar_t * wcp, int nsz, wchar_t * wcfilepath) {
wfstream wf;
codecvt_utf16<wchar_t, 0x10ffff, little_endian> ccvt(1);
locale wloc(wf.getloc(), &ccvt);
wf.imbue(wloc);
[Code] ....
Output:
save bytes succeeded
1234 5678 9ABC EF12 ABCD FE21 DCBA 1F2A EFFF 02FF
read bytes succeeded
nsz =: 20
Now, if wbuf[8] = 0xefff; is replaced by wbuf[8] = 0xffff;
Output:
save bytes succeeded
1234 5678 9ABC EF12 ABCD FE21 DCBA 1F2A 02FF
read bytes succeeded
nsz =: 18
Obviously, the 0xffff wbyte is not read. WHY ?
This presents a significant problem when attempting to read ALL wbytes from a file.
how to accommodate double-size:8 bytes in 4 bytes pointer in 32bit system.
View 1 Replies View RelatedCode:
int i12 = 1001;
cout << i12 << " " << &i12 << endl;
gives the result: 0x7fff0d065098
It's 6 bytes, but I'd expect the address to be 8 bytes on my 64 bit machine. I am using Ubuntu 12.04, GNU compiler.
So, why the address is 6 bytes and not 8 bytes?
Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.
View 6 Replies View Relatedto return the array i shall make a pointer function thats ok.. but how do I get the size return if i dont know the size?
if I need to make AXB=C and output C my new array doesnt have a size..
I am currently reading several values one after another from a file like so:
Code: ifstream f;
double x;
double a, b, c, d;
f.read((char *)&x, sizeof (double));
a = x;
f.read((char *)&x, sizeof (double));
b = x;
//etc ... for several other values Question:
How can I read every (lets say) 3rd value instead of every next value from the file
m_sName-- character array shall be 128 bytes
How do i create a character array that has 128 bytes?
Using a table with the 256 bytes as strings, said table is used as a reference in the 2 functions of this code. Functions who make the conversion such as the title establishes, and in the inverse way too.
The main advantage is that you don't need any knowledge about managing bytes with c++..
Code:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
char* hextabla[] = { //256 BYTES
"00","01","02","03","04","05","06","07","08","09",
"0A","0B","0C","0D","0E","0F","10","11","12","13",
[Code] ....
I leave the project in MSVCPP 6, see attachment...
It's ready to compile in 'Release' mode.
Here's the code that returns maximum sum of a subsequence from a given array. This is according to "Programming Pearls" by Jon Bentley. I have come up with an example for which this program won't work. And here's that example:
{ -10, 11, 10, -10, 2, 3, -6, 1 }
Max subsequence sum above is 21. 2nd and 3rd elements.
But the program returns 16. It sums 2nd through 6th elements and returns. Why would the writer explain something with such depth, only to give a program that doesn't work in all instances?
int MaxSum(int lo, int hi, int* arr) {
if (lo > hi) {
return 0;
}
if (lo == hi)
[Code]...
I'm currently working on a program that writes an array of struct to a file and then read back the data from the file to another array of struct. At the bottom is an image of my result.
My goal is to end up with two identical struct arrays but my program fails to do this. My struct have to members: ID and kind (of animals in this case). I declare my first arraystruct africa[] with "monkey" and "giraffe" with their respectively IDnr: 112 and 555. I stream this data to a file and read read them back to the arraystruct get_animal[]. Simply I want the get_animal[] to be identical with the africa[] when the program is over, but that is not so. According to my result(bottom image) it display:
112, monkey (get_animal[0])
112, monkey (get_animal[1])
meaning that get_animal[0] is identical to africa[0] get_animal[1] is also identical to africa[0]
but why? I want get_animal[1] to be identical with africa[1]. meaning I want the result to look like this:
112, monkey
555, giraffe
I've also made the program to print the parameters of my fwrite/fread calls. Why is the 3rd parameter = 1 meaning that only 1 element will be read/written when my program just read/write 2 elements?
Code:
main(){
FILE *fp;
struct animals
{
int id;
char kind[20];
} africa[1] = {{112,"monkey"}, {555,"giraffe"}};
}
[code]....
I'll process the raw content of a stream which obviously will be loaded one chunk at a time into an buffer.I need to check if every chunk content is x00 filled. If it is, I'll increase the blank chunks counter of 1.On your personal opinion, which is the fastest an less cycles consuming manner to achieve such result?
I was wondering this: is it possible to make an instant XOR of all the buffer content to check if it does return 0 ?the only way is it to cycle through all the bytes and compare each one of them with 0?
I followed a tutorial to load a bitmap from file and convert it to a array of bytes to access it directly. Now to display the bitmap on screen do I have to convert it to a HBITMAP or can I display it from the array of bytes?
Also the program I am building is a calendar program and I need to know if I can manipulate the bitmaps pixels in the byte array (e.g change color and resize image)
here is the code to load the bitmap
HTML Code:
BYTE* Sprite2::LoadBMP(int* width, int* height, long* size, LPCTSTR bmpfile ) {
BITMAPFILEHEADER bmpheader;
BITMAPINFOHEADER bmpinfo;
DWORD bytesread;
HANDLE file = CreateFile(bmpfile,GENERIC_READ, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0);
[code]....
I have an assignment which requires me to do the following:
Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:
- The first parameter is the array to be searched
- The second parameter is the integer to be found within the array
- The third parameter is the size of the array
- The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.
Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)
Code:
#include <stdio.h>
#define SIZE 10
size_t findNumber(int *sort, const int array[],int key,size_t size);
int main(void){
int a[SIZE];
size_t x;
[code].....
I am trying to write a function to reverse a wav file. The idea is to copy the header as it is from the begening of the input.wav file to the beginning of the output.wav file. After that i have to take count number of bytes(count = numberChannels * bitsPerSample in the wav i use this is 2*16= 32 bits, 32/8 = 4 bytes). With this code i am trying to copy the header( that's working fine) and then copy 10 samples from the end and put them to the output.wav file(after header not at the beginning).
This is the content of the input file:
The last 4 bytes of the header are bolded.
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 00 10 00 10
ff 00 10 00 00 10 00 10 00 00 ff 10 10 10 00 10
00 00 00 10 10 10 10 00 00 00 10 00 10 00 10 ff
00 10 00 00 10 00 ff 00
This is the content of the output file it suppose to have in my example
Code:
52 49 46 46 24 bd 01 00 57 41 56 45 66 6d 74 20
10 00 00 00 01 00 02 00 44 ac 00 00 10 b1 02 00
04 00 10 00 64 61 74 61 00 bd 01 00 10 00 ff 00
00 10 00 00 10 00 10 ff 00 00 10 00 10 10 10 00
00 00 00 10 10 10 00 10 00 00 ff 10 00 10 00 10
ff 00 10 00
Code:
void reverse(char **array) {
int i=0;
word numberChannels;//word is unsigned short int , byte is unsigned char
word bitsPerSample;
[Code] .....
The problem is that (having in mind per sample is 4 bytes) instead of copying 40 bytes it just copies 20
I try to crypt file with XOR instruction, by always receive segmentation fault. What's wrong with it?
Code:
#include <stdio.h>
main() {
FILE *fin,*fout;
char buff[40];
int a=0x11;
int i=0;
[Code] ....
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit
[Code]....
I need to do a function that copy every word from a text to a char word. How can i do it?
View 5 Replies View RelatedI wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.
decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.
whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?
Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/
#include <stdio.h>
#include <stdlib.h>
[Code] ....
I have the following code which attempts to assign a u_int8 array of 256 to an unsigned char[256]:
Code:
unsigned char testData[256]=pSample->data;
I get the compilation error:
error C2440: 'initializing' : cannot convert from 'const uint8_t [256]' to 'unsigned char [256]'
What is the safe way to cast or convert here?
I am trying to get each step down before proceeding to the next one for my problem. I have started my program into returning the Area and Volume of a cylinder. The return numbers I get are huge and I cannot figure out why.My header file
class cylinderType {
public:
void getRadius(double rad);
void getHeight(double heigh);
double area();
double volume();
[code]....
I am writing code to multiply two int arrays and in my one function i am trying to convert the char array into an int array. I have tested many parts however i can not find the problem.
Code:
struct integer* convert_integer(char* stringInt){
struct integer *converted = malloc(sizeof(struct integer));
int length, i, *ints;
ints = (int *)malloc(10001 * sizeof(int));
length = strlen(stringInt);
printf("stringInt: %s with length of %d
", stringInt, length);
converted->size = length;
[Code]...