T
Tyler
For starters here is the homework question:
read a string and print it in reverse (25)
reverseString function doesn't return anything
use one parameter
read a set of integers save them into an array and print the set in
reverse (25)
reverseInteger
use two parameters (array and size)
maximum array size is 100
use a loop to read values, stop when a user enters 'y'
Do Not print in reverse functions
Bonus
If you use pointers to swap values in reverse functions (10)
if you implemented with multiple files and Makefile (10)
essentially, I think my teacher wants us to modify the array/strings
globally but I'm not really sure how to do that and I'm getting some
funky errors with my code. However I think I'm really close.
Here's my code:
main.c
/*
* main.c
* hw_L9
*
* Created by Charles Cothren on 4/8/12.
* Copyright 2012 Syracuse University. All rights reserved.
*
*/
#include "reverseop.c"
#include <stdio.h>
int main ()
{
char part1string[100] = {0}, stop;
int part2array[100] = {0}, i = 0;
//Part 1
printf("Enter the string you would lik to reverse: ");
gets(part1string);
reverseString(part1string);
printf("Your string in reverse: %s", part1string);
//Part 2
printf("Integer Set Reverser\n");
while( stop /= 'y')
{
printf("Enter an the next integer: ");
scanf(" %d", part2array);
i++;
printf("Do you wish to stop? (y/n): ");
scanf(" %c", &stop);
}
reverseInteger(part2array, i);
printf("Your integers in reverse: %s", part2array);
return 0;
}
reverseop.c
#include <stdio.h>
void reverseString(char *strng);
void reverseInteger(int *arrayset[], int size);
void reverseString(char *strng)
{
int q = 0, i;
char strng2[strlen(strng)];
for (i = (strlen(strng)-1); i >= 0; i--)
{
strng2[q] = strng;
q++;
}
for (i = 0; i < (strlen(strng)-1); i++)
{
strng = strng2;
}
}
void reverseInteger(arrayset[], size)
{
int q = 0, i;
char arrayset2[size];
for (i = (size-1); i >= 0; i--)
{
arrayset2[q] = arrayset;
q++;
}
for (i = 0; i < (size-1); i++)
{
arrayset = arrayset2;
}
}
I get the error expected ) before ] token on this line and I don't
understand why
void reverseInteger(arrayset[], size)
read a string and print it in reverse (25)
reverseString function doesn't return anything
use one parameter
read a set of integers save them into an array and print the set in
reverse (25)
reverseInteger
use two parameters (array and size)
maximum array size is 100
use a loop to read values, stop when a user enters 'y'
Do Not print in reverse functions
Bonus
If you use pointers to swap values in reverse functions (10)
if you implemented with multiple files and Makefile (10)
essentially, I think my teacher wants us to modify the array/strings
globally but I'm not really sure how to do that and I'm getting some
funky errors with my code. However I think I'm really close.
Here's my code:
main.c
/*
* main.c
* hw_L9
*
* Created by Charles Cothren on 4/8/12.
* Copyright 2012 Syracuse University. All rights reserved.
*
*/
#include "reverseop.c"
#include <stdio.h>
int main ()
{
char part1string[100] = {0}, stop;
int part2array[100] = {0}, i = 0;
//Part 1
printf("Enter the string you would lik to reverse: ");
gets(part1string);
reverseString(part1string);
printf("Your string in reverse: %s", part1string);
//Part 2
printf("Integer Set Reverser\n");
while( stop /= 'y')
{
printf("Enter an the next integer: ");
scanf(" %d", part2array);
i++;
printf("Do you wish to stop? (y/n): ");
scanf(" %c", &stop);
}
reverseInteger(part2array, i);
printf("Your integers in reverse: %s", part2array);
return 0;
}
reverseop.c
#include <stdio.h>
void reverseString(char *strng);
void reverseInteger(int *arrayset[], int size);
void reverseString(char *strng)
{
int q = 0, i;
char strng2[strlen(strng)];
for (i = (strlen(strng)-1); i >= 0; i--)
{
strng2[q] = strng;
q++;
}
for (i = 0; i < (strlen(strng)-1); i++)
{
strng = strng2;
}
}
void reverseInteger(arrayset[], size)
{
int q = 0, i;
char arrayset2[size];
for (i = (size-1); i >= 0; i--)
{
arrayset2[q] = arrayset;
q++;
}
for (i = 0; i < (size-1); i++)
{
arrayset = arrayset2;
}
}
I get the error expected ) before ] token on this line and I don't
understand why
void reverseInteger(arrayset[], size)