The function takes in a parameter i.e. a char pointer. It handles the parameter as a Cstyle string i.e. a NULL terminated char array. It does not make use of the stringclass or its associated functions. In other words, the function examines every char element in the array until it encounters the terminating NULL character.
Starting from this int main :
int main() { char string1[] = "Application of C++"; printPattern(string1); }
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size) { int temp; int smallest; int current; int move; }
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
In this code, i declared a string constant and trying to print the length of string. I know that if i write char a1[7] or char a1[] than it runs and give aggregate output, but in this case it is giving double length of string.
Trying to append a comma to a string. Getting "Segmentation Error" on Solaris when the function is entered the second time.
Code:
// Appends a comma to the given string void appendComma(char* instring) { if (instring == NULL) { instring = realloc(NULL, strlen(",")); strcpy(instring,",");
1. Create a variable named index and nitialize it to zero(0) 2. Prompt for and input a string value from thekeyboard. Store the string inthe string variable newstring[80]. 3. While (newstring[index] does not equal ‘ ’).
i. Display the character at newstring[index] followed by a NL ii. Increment index ====================================== ...
And this is what i have done so far and i dont know where I am wrong ...
Code: #include<stdio.h> int main() { int index = 0; //initialize index to zero since first elementin an array is numbered zero char newstring[80];
Here's what I have to do: Using strcpy() pass it two strings of characters (such as a name like John Johnson) and copy the second string into the first, in reverse order, and print both. Write a main to exercise your function and to illustrate that the function is working properly.
I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :
For i = 3;
Text[0] : I learn class String# Text[1] : I dont learn class String# Text[2] : String#
It print me like that : Text[1] :
I dont learn class String More than that look at the next example :
For i = 3;
Text[0] : I learn class String#abcdef Text[1] : I dont learn class String# Text[2] : String#
You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :
Text[1] : abcdef I dont learn class String
#include<iostream> #include<string> using namespace std; int main() { string text[100], cuvant; int i, j, m, lung = 0; cout << "
I'm trying to make a program in C where the user enters a string and it prints a word for example (name) in lowercase then the same word again but in capitals and lowercase like this (NnAaMmEe).
Given this sentence as an input: "Hello my name and "John" (with its spaces and capital letters), print it on the screen .. NB the phrase must be entered from the keyboard all at once ... you can do this in C / C + +?
I have a problem. I need to print the string called "last" in uppercase format. can you check why my program prints nothing.
Here is the important section of the code.
if (infile.is_open()) // if file was able to open { string line; while (getline(infile, line)) { string::size_type pos1 = line.find(' '); //pos1 is the position of the first space
I need access to the string using the int and the int using the string. Or just direct access to one or the other. . . It's just confusing that they're technically mapped to one another but I can't really access either of them.
If I have understood well the above code can be a typical example that decribes a memory overlap. Some of data to the destination (str + 2 ) will be copied before its copy.
According to the above example I think there is no quarantee even the restrict to the pointer that we won't have overlap.It is legal to use the same pointer and not other in order to have access on the data.So for this the behaviour is not undefined right?
But how memcpy works? I mean I am taking
Code: HEELLOIR as output rather than Code: HEEEEEIR So the behaviour due to overlap is undefined?
The const on const void * restrict s2 denotes that data can't change from s2 itself?
I am trying to make a function that allows me to allocate memory to a "mem" variable and setting each of its chunk's status to FREE. FREE is defined as 0. Below is my code of the function.
Code:
int allocate(mem *mm, int num_chunks, int chunk_size) { int i; mem *temp; if((mm = (mem *) malloc((num_chunks + 1) * chunk_size)) == NULL){ perror("Failed to Malloc
[code]...
mem; If my function works the way it should, it should print out five 0 because that is how I set them in the function, but this is not the case. I've looked at my function for 2 hours, but I could not figure out any logical error. Now, I think my problem lies with my limited knowledge of pointer arithmetic. On the other hand, when I insert 1000 as the second argument into my function, it gives seg faults, which is not the case for smaller values like 5, 10, 15, etc.
I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :
1 test 2 dream 3 code
then output (in data.list file) would be:
1 test 2 dream 3 code 3 code
I also changed the program code so that it reads from data.list file. even here it duplicates last line!
so when program reads the info above saved in data.list it would be:
1 test 2 dream 3 code 3 code 3 code
here's the code for writing:
#include <stdio.h> int main( void ) { int num; char str[80]; FILE *fPTR; fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X
[Code]...
and the one for reading from file:
#include <stdio.h> #include <conio.h> int main( void ) { int num; char str[80]; FILE *fPTR;
So my assignment is to create a program that calls for a function in main that dynamically allocates an array[3] and then have pointers with multiple levels of indirection and pass them by reference so they are not lost after the function. Here is my code:
Next part is to ask user for two non-negative numbers and then get the length of those numbers and create an array. for the size of each number they input. Then to separate those numbers and add the cross-sums.
I am having some trouble tokenizing some strings in C. I am trying to take in a string dynamically and spit print it to the console tokenized using the spaces as delimiters. I have tried using frets() and scant() as well as playing around with pointer values to no avail.