473,395 Members | 1,558 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

reverse arrays

was needing to build an array that prints backwards ( stringReverse )
and returns nothing. should stop processing and print nothing when null
is encountered. this is what i have so far. was going to build my
function from the call but could not make it compile from this point.



#include <stdio.h>
#define SIZE 30

int main()
{
int loop;

char strArray[ SIZE ] = "Print this string backwards.";
for ( loop = 0; loop < SIZE; loop++ ) {
printf( "%c", strArray[ loop ] );
}

printf( "\n" );
stringReverse( strArray );
printf( "\n" );

return 0;

}

Nov 17 '06 #1
2 1631
simo wrote:
was needing to build an array that prints backwards ( stringReverse )
and returns nothing.
You mean a function.
should stop processing and print nothing when null is encountered.
Encountered where?
this is what i have so far. was going to build my
function from the call but could not make it compile from this point.

#include <stdio.h>
#define SIZE 30

int main()
{
int loop;

char strArray[ SIZE ] = "Print this string backwards.";

for ( loop = 0; loop < SIZE; loop++ ) {
printf( "%c", strArray[ loop ] );
}

printf( "\n" );
stringReverse( strArray );
printf( "\n" );

return 0;
}
Okay, this is the testcode in your homework assignment, where is YOUR code?

Uli

Nov 17 '06 #2
simo said:
was needing to build an array that prints backwards ( stringReverse )
and returns nothing. should stop processing and print nothing when null
is encountered. this is what i have so far. was going to build my
function from the call but could not make it compile from this point.
I've modified your code somewhat. In its current state, it will compile and
run - but it won't reverse the string. All you have to do is write in the
details of stringReverse - which is a poor name choice for an abstruse
technical reason but we'll let that slide for now.
#include <stdio.h>

void stringReverse(char *s)
{
/* 1. find the length of the input - if it's
0 or 1, forget it and return. */

/* 2. get a marker (A) - a pointer or an index - to indicate
the first character in the string */

/* 3. get a marker (B) - a pointer or an index - to indicate
the last character before the null terminator */

/* 4. you'll need a temporary swap space too - a single char will do */

/* 5. for as long as marker A and marker B haven't yet collided... */

{

/* 6. copy the last unswapped-so-far value from
marker B into your temp */

/* 7. copy the first unswapped-so-far value
from marker A to marker B */

/* 8. copy the saved value from the
temp to marker A */

/* 9. add 1 to marker A */

/* 10. subtract 1 from marker B */
}
}

int main(void)
{
char strArray[] = "Print this string backwards.";

printf( "%s\n", strArray);

stringReverse( strArray );

printf( "%s\n", strArray);

return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
9
by: Robert Brown | last post by:
If I use _reverse_ wildcard search will it always result in a table scan? Is it possible to get the DB (Oracle or SQL server) to use indexes when doing reverse wildcard match? let's say I have:...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
15
by: Fady Anwar | last post by:
Hi while browsing the net i noticed that there is sites publishing some software that claim that it can decompile .net applications i didn't bleave it in fact but after trying it i was surprised...
9
by: HELLO $$$ | last post by:
From Beginner : I am studying a C++ program, using: char, arrays, etc. The aim of this program is to let it make "Reverse" of any statement (string) as example: if the original string is " this...
1
by: rgtidwell | last post by:
I know this code is wrong, and I am paying the price now for focusing on Linear last semester during the first half of C++, but I am trying to figure this out. Can anyone help? I want to make sure:...
14
by: Faisal Shah | last post by:
Hi, Well, My name is Faisal, You might saw as my ID. I got into php before a few months... I need help.. I am trying to read a file that is .txt format.. Line by Line, Reverse action.. I...
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.