C :: Passing Snprintf Into A Buffer?
Oct 17, 2014
Im creating a permissions profiler in c by using stat()I ran into a problem of getting a bad address as in my path. Ive tried multiple solutions with no dice, and now I have one more solution I want to try but I dont understand how.how do you use a snprintf and pass that into a buffer, and pass that into a path for stat()?
View 9 Replies
ADVERTISEMENT
Oct 29, 2014
I have an int array of size 5 and I have my program to accept 5 integers between 10 and 100 inclusively. I should be able to type integers over and over again until I get 5 that are in the range, 10 <= x <= 100. Now when I get 5 that fall in that range the program should continue but instead it wants a 6th number before continuing. I'm suspecting the program is hanging on to a new line character. Anyway to ignore the new lines? Couldn't find anything for C# without clearing the screen.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DupElim {
//dup elimination
[code]....
View 5 Replies
View Related
Jan 12, 2015
I`ve wrote a function for my utility to XOR char* buffer by a key, then to reverse it with the same key. Here is the code, it`s simple enough:
Code:
static inline char* XOR_buffer(const char* d, const char* k ) {
char *newstr = (char*) malloc(sizeof(char)* strlen(d));
newstr[0]='';
printf("%d is size of string
", strlen(d));
char *begin = newstr;
char* ret = begin;
int len = strlen(k);
}
[code]....
The lengh of the string is reduced by the second XOR call. You can try it out, just define XORDBG to view the error message in the second pass to the buffer.
View 9 Replies
View Related
Feb 5, 2014
I want to use a const char* as a buffer. I am reading values from a file and adding them to a buffer. How to extract the values is simple enough. I am reading through a filestream, reading each character into a char pointer and progressing that char pointer every time. I have another char pointer marking the start positon
eg.
char *mychar = new char;
char *char1 = new char;
char *char2 = new char;
const char *constchar ;
char2 = char1;
while(filestream.read(mychar,1) {
*char1 = *mychar;
++char1;
}
Then I get this problem: constchar = mychar; // const char* = char*.
Constchar does not catch all the data in other words. At some stage some data is lost due to zeros in the data.. How can I put values into a const char and get around this problem? The const char* will //only record everything up until the first zero.
View 6 Replies
View Related
Aug 22, 2014
suddenly nothing is written to my file
void taglessLine(char line[],ofstream& buffer){
buffer.open("buffer.txt", ios::out);
int len=strlen(line);
[Code].....
View 2 Replies
View Related
Dec 17, 2014
get some opinions on, or established methods on how your buffer size should be decided.
View 2 Replies
View Related
Oct 10, 2014
I am writing a program and am asking the user to enter a number between 1-12.
If they do not, they will be promoted over and over again to enter a number between 1-12.
However, if the user enters a letter or anything else scanf seems to stop working and then my loop goes out of control.
View 2 Replies
View Related
May 9, 2012
I'm trying to analyze buffer text, but unfortunately i'm not able to do so... My approach
Code:
// here i'm getting and reading text from the user
bzero(buffer, 1024);
read(m_Socket, buffer, 1023);
string inputText;
inputText = string(buffer);
[code]....
View 2 Replies
View Related
Apr 13, 2014
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?
View 14 Replies
View Related
Jan 3, 2014
Code:
char buffer1[10];
char buffer2[10] = "something";
sprintf(buffer1, "with %s", buffer2);
In a statement like the one above, is there a threat/leak or does it only truncate the string that is loaded into buffer1?
View 5 Replies
View Related
Jul 11, 2014
How to assign numbers stored in a buffer memory to a 2D array.
The data type is unsigned 16bit (unsigned short) integers and they are stored in a 16bit/2bytes*1280*1024=2621440 bytes memory. The pointer pBuffer is the starting address of the buffer. Now I initiated an array and then assign the numbers to the array.
Code:
unsigned frame[1280][1024];
for (int i=0;i<1024;i++){
for(int j=0;j<1280;j++){
frame[i][j]=(*(unsigned short*)pBuffer+1024*i+j);
printf("%u ", frame[i][j]);
}
printf("
");
}
Because I know the number in the memory, I know after running the code that the result gives me nonsense.
I tried frame[i][j]=(*(unsigned short*)pBuffer+1024*2*i+2*j);
Since I think the pointer needs to move 2 bytes at a time, but it still gives me nonsensical array back.
Am I using the wrong expression to assign the values?
View 3 Replies
View Related
Jul 10, 2014
I am having some issue with clearing cin buffer. The following code does not wait for me to see the output window and till I hit return character.
#include "iostream"
#include "stdio.h"
#include "math.h"
#include "string"
#include "sstream"
using namespace std;
[Code] ....
I tried
cin.flush, cin.ignore(numeric_limits<streamsize>::max(), '
'); cin.clear(); fflush(stdin);.
None of them worked
I am working on Microsoft visual studio express 2013 for windows desktop.
View 3 Replies
View Related
Aug 7, 2014
When the program is processing/sleeping, those char input at that time would not goes into the buffer until the next input request (such as calling istream::get). The program below shows this.
#include <iostream>
#include <streambuf>
#include <chrono>
#include <thread>
int main() {
std::cout << "Sleeping...
[Code] ....
I wonder if there is a way to distinguish between the input comes from the time that does not request it (i.e., during processing or sleeping) and those comes after the time does request it (in the example, after "Input something: ").
View 3 Replies
View Related
Sep 25, 2013
How do you read an int choice in with a string buffer instead of cin?
View 2 Replies
View Related
Oct 2, 2013
I have problem with this code:
#include <windows.h>
#include <stdio.h>
#include <gdiplus.h>
#include "ScreenCap.h"
#include <wchar.h>
#include "base64.h"
#include <sstream>
using namespace Gdiplus;
int GetEncoderClsid(WCHAR *format, CLSID *pClsid) {
[Code] ....
This function return me a long series of Y ended with other chars but not the base64 string.
I think the problem is std::string encodedstring = base64_encode(buffer, dwBufferSize); but I can't figure out the problem.
The base64 function is: [URL] ....
View 2 Replies
View Related
Jan 20, 2015
I already wrote:
strncpy(buff2, buff1[i], strlen(buff1)-i );
but this function seem to just copy from the beginning of a buffer to another, not from the ith element.Is there such a function?
Buff1&buff2 are char[10000] and i is declared int, holding the interesting element's position.
View 4 Replies
View Related
Nov 19, 2012
Got buffer with raw data. How to display it in MFC dialog and refresh it?
View 3 Replies
View Related
Jan 27, 2013
how to create, initialize, and maintain a memory device context that works as a local buffer for images? The idea is to maintain some large images in local DCs and bitmaps, and only bitblt them to screen in OnDraw().
What I did so far was was to define CDC and CBitmap objects as members of my View class, and then tried to initialize them with the sequence that begins at "// Initialize buffer". I placed that sequence in either OnInitialUpdate, or PreCreateWindow, or OnPrepareDC, or the view constructor, to no avail. The code always crashes in OnDraw, and I've noticed that the m_hDC member of myDevice is zero at that point.
Obviously, the initialization is wrong and MFC does (too many) things in the background which I'm not aware of.... My question was where can I read about that?
Code:
class CMyView : public CScrollView {
// ...
CDC myDevice;
CBitmap bmp;
CBitmap *oldbmp;
[Code] .....
View 5 Replies
View Related
Dec 9, 2014
I use new to allocate a buffer, as follows:
BYTE *p;
p = new BYTE[20];
...
delete p;
After p is deleted, if I do NOT assign NULL to p, is there a way to determine whether it has already been freed?
View 4 Replies
View Related
Mar 30, 2012
buffer.h
Code:
#ifndef BUFFER_H
#define BUFFER_H
typedef int buffer_item;
class Buffer
[Code]....
Why am I getting a segmentation fault?
I'm thinking that either my random is adding some number that's out of range as an index, despite my % that should prevent it ! , or it's trying to remove from an invalid index or something.
View 5 Replies
View Related
Mar 29, 2013
I plan to read one character at a time from a very large text file.
The tokens that I would like to extract are basically words and they are delimited by varying numbers of spaces or tabs.
For example, the first line has two words separated by five spaces:
Joe Mark
Problem:I apply get() each time advancing towards Mark. For me to know ive reached the next token, Mark, I merely have to get() until it equals 'M'. The problem by then its too late as Ive already captured 'M'. I somehow need to capture the fifth space and the code must "know" the next character is 'M' without getting() it.
Kernighan and Richie offer us a function getch() and ungetch() whereby the ungetch pushes back the last character into the input . The problem with this is that I believe is that the buffer is not the actual input buffer stream but rather a simulated character array which contains the input. I dont think itll be as efficient on a text file so large.
View 9 Replies
View Related
Jan 20, 2014
I have a C program. Within it, I would like to embed either a file or a pre-assigned variable. I would prefer a method that is platform independent.
I am using the data type "RSA" from <openssl/rsa.h>. I have a key file in PEM format, but I would like to embed an RSA object in the program instead. I tried creating a char array and then casting the pointer, but that caused some sort of illegal casting issue. I tried using memcpy but I haven't been able to get it working that way. What is the best way of going about this? Is it possible to read a file directly from a memory buffer?
View 1 Replies
View Related
Mar 1, 2014
I'm writing a program that communicates with another program over TCP/IP. I need to assemble contiguous buffers of mixed data to send to the server. For example, one of the messages must contain multiple 32-bit integers and 64-bit floats, each in its own appropriate field. I also need to receive and decode similar buffers.
The Windows TCP function "send(socket s,char *buf, int len, flags)" takes a pointer to a character array to send. Likewise, the TCP function "recv(socket s,char *buf,int len,flags)" takes a pointer to a character array to fill. I've tried creating structures describing the send and receive messages, with the fields appropriately laid out. But the CODE::BLOCKS compiler complains when I try to hand send and recv the pointers to the structure variables. Am I on the right track, or is there a better way to do this?
View 2 Replies
View Related
Apr 13, 2013
how to combine a string value with a local buffer containing time and date. I can't seem to get the syntax correct or find an example of this.
So I'll have a result like: The time is: 12:49 04/13/2013. My project will put different values in String mess1 depending on what's happening.
My code
char buf1[20];
String mess1 = "The time is:";
sprintf(buf1, "%02d:%02d %02d/%02d/%4d", hour(), minute(), month(), day(), year());
//mySerial.println(buf1); // operates perfect
mySerial.println(mess1 buf1); // Does not compile - error: expected `)' before 'buf1'
I have also tried a comma between (mess1, buf1), no dice.
View 3 Replies
View Related
May 6, 2014
The documentation of the class filebuf in the reference of cplusplus.com says:
Objects of this class may internally maintain an intermediate input buffer and/or an intermediate output buffer, where individual characters are read or written by i/o operations. These buffers are synchronized with the contents of the file once filled up, when explicitly requested to do so (sync), or when the object is closed.
Objects of this class may be explicitly made unbuffered by calling member pubsetbuf with both arguments set to zero (see member setbuf): Unbuffered file stream buffers perform the i/o operations directly on the file, without an intermediate buffer.
The C++ standard ensures that filebuf objects have an intermediate input/output buffer/s (i.e, the default constructor of the class filebuf creates the intermediate buffer/s)?
The standard C++ library only allows unbuffering filebuf objects (as the above quote says) but doesn't allow forcing filebuf objects to be buffered.
I have been seeying the concrete implementation code of the standard C++ library in my Windows Operating System (Windows 7 Ultimate 64 bits Service Pack 1) and it seems that fielbuf objects never uses intermediate input/output buffer/s, they use FILE streams of the standard C library instead to do the work. Are this FILE streams always buffered? If true, are they fully-buffered or line-buffered? what is the size of the buffers (perhaps macro BUFSIZ from <cstdio>)? and can I change this size?
I am worried about performance in reading and writing from/to files: if the default behaviour offers the best performance (perhaps if files are too large is better force buffering and choose a larger buffer size).
View 2 Replies
View Related
Dec 24, 2014
I am trying to add some functionality to this project: [URL] ...
Under this [URL] ...
This latest comment based on;
host.data = (u_char *) "112.168.231.19:80";
for (i = 0; i < peer->name.len; i++) {
peer->name.data[i] = host.data[i];
}
or more simpler:
peer->name.data = host.data;
States: "Because strings always require an extra memory buffer (and the burden of memory management) while primitive values like booleans and numbers don't."
Which makes sense since a boolean change (down/up) does actually changes a runtime value, however the string replacement shows via '/upstreams' that the value has changed but at runtime it is still using the old value.
So in short it looks like I do need a buffer to change the string value.
My question is why? if 'peer->down' works on a memory fragment where its value resides then why doesn't a 'peer->name.data = host.data' do the same thing? can this be done without a buffer? once you allocate memory and store host.data in to this where do I copy it to?
View 5 Replies
View Related