C :: Weird Characters Popping Up In Fwrite Function

Mar 13, 2013

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {

[Code]....

this code asks the user to input words/strings until he enters "end."after that, the program must copy the input to a text file named read.txt...I entered 'j' and then 'end' and after that I looked at the read.txt file and here's what's in it.

Output:

Code:
j
; end

some weird characters appeared!! the characters in the text file should only be.

View 6 Replies


ADVERTISEMENT

C++ :: Popping From STL Containers

Feb 21, 2014

I've been working on a project that involves storing pointers to dynamically allocated class objects in an STL list, but trying to run it something's going wrong.

list<Actor*>::iterator it;
for(it = m_actors.begin() ; it != m_actors.end() ; ++it)
{
delete *it;

[Code]....

But it seems like that has a memory leak. Does pop_front() just call the destructor for the object, or will it delete a dynamically allocated chunk of memory? If not, how can I do that deletion to avoid a memory leak?

View 4 Replies View Related

C/C++ :: Must Return A Value Error Keeps Popping Up

Apr 22, 2015

'RationalOperations::hcfCalculation' : must return a value
#include<iostream>
#include<cstdlib>
using namespace std;

[Code].....

View 2 Replies View Related

C :: Using Fwrite With Text Output

Mar 9, 2013

I have the following code:

Code:
void Plot(int nx, int ny, double x[350], double y[350], double C_new[350][350], int iplot){
int i, j;
char fname[50];
FILE *fp;

[Code]....

I am then taking the generated file and importing it into a plotting program (Techplot360). It would speed up the importing process if I created a binary file instead of a like above. I know that I need to use fwrite but I am unsure how to handle lines like

Code:
fprintf(fp, "TITLE= ABCDEFG_%d
", iplot); and

Code: fprintf(fp, "%f %f %f
", x[i], y[j], T_new[i][j]);

View 6 Replies View Related

C :: Using Fwrite And Fread On Structs

Jul 20, 2014

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]....

View 3 Replies View Related

C++ :: Fwrite - Calculating Elapsed Time

Jan 24, 2013

I have a question. I would like to actually have some measure of roughly how long it takes to do a fwrite to a drive. When I do the following:

clock_t begin = clock();
unsigned long long size_t = fwrite(send, 1, transfer_size*sizeof(unsigned long long), wpFile);
clock_t end = clock();
double long elapsed_secs = double long(end - begin) / CLOCKS_PER_SEC;

Unfortunately, I don't get any different result for different transfer size!!!

My guess is that the clock_t , once it issues a fwrite command, some how stops its measurement, and it comes back again, when I am already done with fwrite. I do get the almost same measure, whether my transfer size is 32KB Byte or 16MB ! Which I was indeed expecting to see a huge difference. I wouldn't really want the exact real timing measure (well off course it will be nice to know); and all I care about is to see some difference in time whether I am doing KB transfer vs MB transfer.

Some rough measurement required of the actual time being elapsed for fwrite function?

View 10 Replies View Related

C++ :: Pointer Of Union And Fwrite Operation

Jul 5, 2013

I have union of pointer.

union {
short *two_int;
int *four_int;
double *eight_real;
char *one_ascii;
// void *v;
};

We have write function which write into file.

fwrite (r.one_ascii, 1, i, outstr);

I found one thing,When we write function, we fill only four int in following way.

r.four_int[0] = x + xoff;
r.four_int[1] = y + yoff;

So my question,we fill four_int but write one_ascii only.As is it union of pointer. So it does not matter. I am using 64bit machine and do not have any issue in 32 bit machine.

For more information: [URL] ....

View 7 Replies View Related

C++ :: Fwrite Calculating Elapsed Time

Jan 23, 2013

I would like to actually have some measure of roughly how long it takes to do a fwrite to a drive. When I do the following:

clock_t begin = clock();
unsigned long long size_t = fwrite(send, 1, transfer_size*sizeof(unsigned long long), wpFile);
clock_t end = clock();
double long elapsed_secs = double long(end - begin) / CLOCKS_PER_SEC;

Unfortunately, I don't get any different result for different transfer size!!!

My guess is that the clock_t , once it issues a fwrite command, some how stops its measurement, and it comes back again, when I am already done with fwrite. I do get the almost same measure, whether my transfer size is 32KB Byte or 16MB ! Which I was indeed expecting to see a huge difference.

I wouldn't really want the exact real timing measure (well off course it will be nice to know); and all I care about is to see some difference in time whether I am doing KB transfer vs MB transfer. Any other function that will give me some rough measurement of the actual time being elapsed for fwrite function?

View 4 Replies View Related

C :: Fread / Fwrite And Fseek (reverse Of WAV File)

Jun 28, 2013

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

View 1 Replies View Related

C :: Crypt File With XOR Instruction - Fread / Fwrite Segmentation Fault

Jan 21, 2015

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] ....

View 4 Replies View Related

C :: Create A Function That Will Take A String Of Characters

Dec 7, 2013

I can not cope with the task.Create a function that will take a string of characters (including spaces) and print the numbers of characters (including commas, periods, etc.) in it. The output will be arranged alphabetically. Distinguish case sensitive!

View 6 Replies View Related

C :: Function To Count Number Of Characters In A String

Feb 1, 2014

I wrote a function to count the number of characters in a string. Curious as to why I have to return x-1 and why x isn't the number of characters.

Code:
int count(char *string){
55 int x = 0;
56 char *p;
57 p = string;
58

[Code] .....

View 4 Replies View Related

C :: Reverse Array Of Characters Using Recursive Function?

Mar 15, 2014

Eg. User input : abcde
Program Output : edcba

I keep on getting weird ASCI symbol in return, I couldn't achieve what I need, and tried debugging for days,

Code: char ar[20];
int len,n=0;
printf("enter the string to be reversed :
");

[Code].....

View 5 Replies View Related

C++ :: Templated Function Using Ofstream Strange Characters

Nov 5, 2014

To generate output data, I'm printing a bunch of vector contents to files. Because the type of variable can differ between vectors, I wrote a templated printing function to print out whatever the content of the vector is. It looks like this:

template <class T>
void SomeClass::PrintVector(std::vector<T>& Values, std::string& outFile) {
std::ofstream out(outFile, std::ios::app);

[Code] ....

I added the fixed because some larger values were being printed in scientific notation. Everything works well. My test code includes 3 vectors of doubles and 3 vectors of unsigneds. All the unsigneds work well and two of the doubles work well, but the third doubles vector prints nonsense unless I disable the fixed.

The calling code is the exact same. I know the values in the vector are correct, because a) if I comment out the "fixed" flag it works, and b) one of the unsigned vectors is sorted based on the values in that double vector (after it is printed, so the sort cannot corrupt the vector print) and works perfectly.

The "nonsense" looks like chinese/weird characters, if that matters.

View 11 Replies View Related

C# :: GetLine Function Which Returns Strange Characters

Mar 11, 2014

I have a big problem with a function, I wrote this function in order to get a line from an HTML (Or XML) file, until a specified delimiter (not always or
... It can be everything..)

Here is my code :

public static String GetLineUntilChar( String url , char delimiter , String postData, String referer, String cookie ) {
try {
Uri uri = new Uri("http://127.0.0.1//site.html");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "application/x-www-form-urlencoded";
if (!String.IsNullOrEmpty(referer))
request.Referer = referer;

[Code] .....

View 14 Replies View Related

C :: Print Multiple Characters To Same File Using Fprintf Function

Nov 5, 2014

I'm new to C and was wondering if it was possible to print multiple characters to the same file using the fprintf function provided in one of the C standard libraries?

View 1 Replies View Related

C/C++ :: Recursive Function To Move Specific Characters To End Of String?

Oct 16, 2014

I am attempting to write a recursive function that, given a string, recursively computes a new string where all the lowercase 'x' chars have been moved to the end of the string.

For example,

moveXs("xxre") --> "rexx"
moveXs("xxhixx") --> "hixxxx"
moveXs("xhixhix") --> "hihixxx"

Below is the code I have written thus far, but it seems to be returning only empty strings.

string moveXs(const string& str) {
string strCopy = str;
if (strCopy.length() <= 1) {
return str;

[Code] ....

View 6 Replies View Related

Visual C++ :: Passing As Parameters To A Function Characters Coded In UTF 8

Apr 9, 2014

I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?

View 2 Replies View Related

C :: Counting Function - Prints All Input Lines That Are Longer Than 80 Characters

Jan 10, 2014

I'm doing an exercise that prints all input lines that are longer than 80 characters. I rather not use any libraries so I decided to write my own function that counts characters to use it in my main program. However when integrate things my function returns zero all the time.

Here is my full code:

/* Exercise 1-17 Write a program to print all input lines that are longer than 80 characters */

#include<stdio.h>
/* Declarations*/
#define MAX_STRING_LEN 1000
int count_characters(char S1[]);
int main() {

[Code] .....

So I was trying to debug my count_characters() function and this is the code if I was to run it seperately:

Code:
#include <stdio.h>
/* counts character of a string*/
main() {
int nc = 0;
int c;
for (nc = 0; (c = getchar()) != '
'; ++nc);
printf("Number of characters = %d
", nc);
}

which works...

View 1 Replies View Related

C :: How To Print Characters But No String Just Array Of Characters

Mar 20, 2014

so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?

Code:

int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);

[Code]...

View 6 Replies View Related

C/C++ :: Find The Common Characters Between Two String Characters

Jul 6, 2014

Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '';
int size1,i,j,temp;
printf ("Input the first string");

[Code]...

View 6 Replies View Related

C/C++ :: Check For Set Of Characters In Array Of Characters?

Mar 26, 2014

I have an array of characters. I am trying to find "houston". The only way I can think of to do this is to use a for loop and check each individual character. Is there an easier way to do this?

char string[] = "Fishing tourism miami atlanta dallas houston";

View 9 Replies View Related

C :: File Operations - Fwrite Padding Extra Data In File Compare To Data Provided As Input

Oct 28, 2014

I am trying to write my files to another subfolder . Below is my program.

Code:
cat th6.c
#include <pthread.h>
#include <stdio.h>
#include <string.h>

#define SIZE 8
#define NUMELM 8

[Code] ....

I observe my filename along with directory as text in the new file created in sublfolder. This is output.

[cporgs/apue/threads]: mkdir first
[cporgs/apue/threads]: ./a.out test.txt first
test.txt -- first/test.txt
dfdfdfdfdfdfdf-14
dfdfdfdfdfdfdf-14
in thread test.txt first
[cporgs/apue/threads]: cat first/test.txt
dfdfdfdfdfdfdffirst/test.txt
[cporgs/apue/threads]: cat test.txt
dfdfdfdfdfdfdf

I could not able to get from where this filename and folder is getting added.

View 4 Replies View Related

C :: Cannot Print Characters In The End

Feb 7, 2014

I cant print the characters in the end.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *arquivo1,*arquivo2,*arquivo3;//files i will open//
char texto;//texto= character i will read.

[Code]...

View 5 Replies View Related

C++ :: How To Use Unicode Characters

Jan 25, 2015

I'm trying to have a button marked by the sqrt sign, '√'.

I wrote below code and typed that sign by holding down "alt" and typing 251 using numpad. But result is the question mark instead of sqrt mark!

My machine is Windows 7 x86 and IDE is visual studio 2012.

#include <GUI.h>
using namespace Graph_lib;
//---------------------------------
class Test : public Window {
public:
Test(Point, int, int, const string&);

[Code] .....

View 3 Replies View Related

C++ :: How To Do Substring To Get Last 4 Characters

May 8, 2013

let says i have char *yytext = "p103_stb" 0r "p0_stb" or "p100_stb"

How to do substr to get the "_stb" in C?

View 12 Replies View Related







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