C++ :: Printing Name In Reverse Using Pointers
Jan 25, 2015There is alien code.
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
using namespace std;
char printReverse(char*);
[Code] ....
There is alien code.
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
using namespace std;
char printReverse(char*);
[Code] ....
How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nwords(string);
[Code] .....
I'm currently learning how to work with linked lists, specifically, doubly linked lists, and I have come across a problem with my program when I attempt to print it backwards. Here is the portion of the code :
#include <iostream>
using namespace std;
struct node {
int data; //int to store data in the list
node *next; //pointer to next value in list
node *prev; //pointer to previous value in list
[Code] ....
The purpose of this program is to create a list, print it forwards, backwards, insert an element, erase an element, and then destroy the list. I have chopped it down to just the create, print forward, and print backward functions.
The issue I have is that in the createList function I am modifying both begin and end but I can only return one or the other. This means that whichever I don't return is still NULL in the main function and therefore does not point to anything. I've tried setting the begin/current/end to not equal NULL but createList won't work if I do that.
How I could modify both? Just to be clear, the list HAS TO be created in a function, it would be very easy to just initialize it in the main...
I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried
Code:
int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",
[code]...
the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..
I am a little confused while comparing char pointers to integer pointers. Here is the problem:
Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";
When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;
As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};
If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??
How can I reverse/toggle bit like 1 to 0 and conversely, 0 to 1?
For instance: 01000100 ('D' 68) to 10111011 ('╗' 187).
Is there any way easier and more simple than:
1. Convert char/string to binary.
2. Toggle bits.
3. Convert binary back to char/string.
If I am executing following code after reversing it is giving "1" but I need "0001".
#include <stdio.h>
int main() {
int n=1000, reverse = 0;
while (n != 0) {
reverse = reverse * 10;
[Code] .....
I would like to add a new function to my class, "reverse" that would reverse the order of the list. I have added a prototype in the "public:" section of the code (see the comment with PROTOTYPE in it). Your task is to complete the implementation (see the comment with IMPLEMENTATION in it. See the main() function to see how the results should look
#include
#include
using namespace std;
class List {
public:
// Constructs an empty list
List();
[Code]....
I cant seem to get the right function to put into reverse I have tried everything Im not sure where to start!
I have written a code to find reverse of a number and print if if the original and reversed numbers are equal or not .the problem is in the if condition where the first printf is not working at all. the code is
#include <stdio.h>
#include <conio.h>
int main (void)
{
[Code]....
as if i enter 121 it still shows the 2nd printf instead of 1st one. sort out the bug;;!
I was browsing the web looking for simple yet fun programming challenges and crossed this one. I figured out how to reverse the string in place but I want it to read "blue is house the". I approached it in two ways for the heck of it. My idea was the second one, the first one I googled. I didn't know a simple rbegin() could do that, pretty neat.
I found the question here.[URL] ....
Code:
#include <iostream>
#include <string>
int main(int argc, const char * argv[])
{
std::string phrase = "The house is blue.";
[Code] ......
"Destructors for a derived class object are called in the reverse order of the constructors for the object. This is a general rule that always applies. Constructors are invoked starting with the base class constructor and then the derived class constructor, whereas the destructor for the derived class is called first when an object is destroyed, followed by the base class destructor."
But why, or is it just because, so programmers know which one and modify their destructor accordingly??
I am trying to write a program that reverses the elements of an array by using an function 'myreverse'. The function should reverse original array and return nothing.
In my program, the function 'myreverse' is not getting invoked and the original array is being displayed as it is.
#include <iostream>
using namespace std;
void myreverse(int arr[],int n) {
int *p=&arr[n-1];
int temp;
for(int i=0;i<n;++i)
[Code] .....
I am trying to write a program in which i enter sentences and then gives the reversed output
E.g.: -
INPUT
Enter the number of sentences
3
This is a sentence
Program
You are great
OUTPUT
sentence a is This
Program
great are You
I wrote the following code but its failing when im trying to enter a sentence
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void str(char*, int);
void main() {
char *word[25];
[Code] ....
I am working on a project where I need to reverse bits for a number.
For example, if I have 110111100000000 I need to reverse it to 0000000001111011.
As part of my hw assignment i need to reverse a string using stacks. This is my attempt and so far its not working.
// reverse.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
[Code].....
If we have a text file containing the string: abc, how to reverse it to be cba using file open modes (ios::app, ios::ate, ios::binary, ios::trunc, ios::in and ios::out)?
View 19 Replies View RelatedI have a problem with my code. I just have to reverse the chars of a string, but it adds a /n that I can't delete.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ch05Ex05._5 {
[Code] ....
I have to write a program to reverse a sentence like
cat
tac
But my program is case sensitive. Like if i enter sentence it gives me ecntenes(which is wrong). How to make it non case-sensitive using vectors?
// BackWardsSentence.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string BackWords (string sentence);
[Code] ......
I have been trying this for so long. I need to make a separate function named reverseDiagonal where I have to reverse the diagonals in a 2D array.. I have tried swapping it but i don't know where to place the "cout" and print the diagonal.
View 4 Replies View RelatedWrite a C program to read the list from the file and store them in the arrays. Your program should write the list of client's account number, client's name and the client's balance to another file called "newdata.txt" in reversed order and also display them on the screen.
An example of output dialog is shown below
Account Name Balance
800 Stacy 100.10
700 Michael 81.05
600 Dale 1005.30
500 Richard 214.89
400 Stone -45.23
300 White 0.00
200 John 345.67
100 Jones 24.50
--------
This is what I have done so far bellow here....But the only missing part is the reversed order of 'newdata.txt'contents.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
FILE *ifpt,*ofpt;
[code]....
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
Im writing a c program that reverses the words in a sentence,
Example:
you can cage a swallow can't you?
you can't swallow a cage can you?
I have it all working, except the fact that I dont know how to get the words themselves to turn around. Heres my code and an example of the output im getting.
Output Im getting:
Enter a sentence: you can cage a swallow can't you?
Reverse of sentence: uoy t'nac wollaws a egac nac uoy?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 200 /*Decent number of chars for a sentence*/
int main()
[Code] ....
I am new to C and trying to reverse a string but the function is not getting called.. the console says :
Enter a stringabhi
bash: line 1: 229 Segmentation fault (core dumped) ./program
Code:
#include<stdio.h>
#include<math.h>
#include<string.h>
char* reverseString(char input[]);
void main()
[Code] ....
I was assigned to reverse a unidirectional linked list in C, where I'm not allowed to make a copy of the given linked list, or to change the actual data.
The only thing I'm allowed to do is to manipulate the list's pointers. After doing some thinking and scribbling on a piece of paper, I came up with this:
Initialize three pointers: p1,p2,p3, for the first, second and third elements, respectively.
p1->next=NULLwhile (p3 != NULL) do p2->next=p1p1=p2p2=p3p3=p3->nextp2->next=p1return p2
as the head of the reversed list
This is a pseudo code, of course, as I'm less interested in the actual implementation, and more about the algorithm itself. I was wondering if there's a more elegant way of doing this, since this gets quite complicated considering the cases where the list has less than three elements in it.
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <math.h>
void reverseAr(char ar[], int n);
int main() {
int choice;
char *abc= ar[];
[Code]...
My codes keep couldn't get the reverse array of characters.
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.
View 4 Replies View Related