can anyone help me. whats wrong with my code. fix it please. here is my code//\\
ID: 3604721 • Letter: C
Question
can anyone help me. whats wrong with my code. fix it please.
here is my code//
h27.cpp
-----------------
#include <string>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
// Other headers if necessary
using namespace std;
#include "h27.h"
// Add your code here
void reverse(char * s)
{
char * strptr = s;
char * beg = s;
char * end = &s[0];
char * ch;
while(*end != '')
{
end++;
}
end--;
while(beg < end)
{
ch = beg;
beg = end;
end = ch;
beg++;
end++;
}
cout << end << endl;
}
//h27.h
#ifndef H27_H_
#define H27_H_
/**
* Reverses the C-style string pointed to by s.
*
* @param s a pointer to the character in a C-style string.
*
* NOTE: for this assignment, you can only use ++, --,
* = (assignment), ==,!= (comparison) and pointer subtraction
* (p1 - p2). You cannot use pointer arithmetic (s + i), or
* array notation (s[i]). In fact, you cannot have ANY integer
* variables or literals in your code. You also cannot use ANY
* standard library functions including strlen.
*/
void reverse(char * s);
#endif
// DO NOT CHANGE ANY OF THESE LINES
#define strlen(s) static_assert(false, "strlen not allowed");
#define strcat(d, s) static_assert(false, "strcat not allowed");
#define strcpy(d, s) static_assert(false, "strcpy not allowed");
#define string static_assert(false, "string not allowed");
Explanation / Answer
#include <string>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <stdio.h>
// Other headers if necessary
using namespace std;
#include "h27.h"
int main(){
char Cstring[50];
cout<<"enter a word: ";
cin>>Cstring;
string results = reverse(Cstring);
cout <<results;
}
void reverse(char * s)
{
char * strptr = s;
char * beg = s;
char * end = &s[0];
char * ch;
while(*end != '')
{
end++;
}
end--;
while(beg < end)
{
ch = beg;
beg = end;
end = ch;
beg++;
end++;
}
cout << end << endl;
}
//h27.h
#ifndef H27_H_
#define H27_H_
/**
* Reverses the C-style string pointed to by s.
*
* @param s a pointer to the character in a C-style string.
*
* NOTE: for this assignment, you can only use ++, --,
* = (assignment), ==,!= (comparison) and pointer subtraction
* (p1 - p2). You cannot use pointer arithmetic (s + i), or
* array notation (s[i]). In fact, you cannot have ANY integer
* variables or literals in your code. You also cannot use ANY
* standard library functions including strlen.
*/
void reverse(char * s);
#endif
// DO NOT CHANGE ANY OF THESE LINES
#define strlen(s) static_assert(false, "strlen not allowed");
#define strcat(d, s) static_assert(false, "strcat not allowed");
#define strcpy(d, s) static_assert(false, "strcpy not allowed");
#define string static_assert(false, "string not allowed");
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.