Apr 5, 2012 at 6:17pm UTC
yes. without the use of libraries like vector for instance...i can use ctype...im sorry for constantly asking for help, but its just that no one is...
Last edited on Apr 5, 2012 at 6:24pm UTC
Apr 5, 2012 at 6:53pm UTC
this is what i did:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include "stdafx.h"
#define SkipSpaces( p ) while( isspace( *( p ) ) ) ++( p )
#define ExtractWord( p ) while ( !isspace( *( p ) ) && *( p ) ) ++( p )
int main( void )
{
char s[80];
char *p = s;
puts("Please enter your sentence" );
for (int i = 0 ; i < 80; i++){
scanf("%c" , s[i]);
}
for (;p<s+80;++p){
s[*p];
SkipSpaces(p);
ExtractWord(p);
}
for (int i = 0 ; i < 80; i++){
printf("%c" , s[i]);
}
puts( "Press any key to continue..." );
getch();
return ( 0 );
}
code returns an error.... :/ can anyone assist me with this
Last edited on Apr 5, 2012 at 6:59pm UTC
Apr 5, 2012 at 7:40pm UTC
Look standard function
fgets to read a whole string until ENTER will be pressed.
char * fgets( char *s, int n, FILE *stream )
I think it is the function you shall use to read a sentence.
For example
1 2 3 4
...
puts( "Please enter your sentence" );
fgets( s, sizeof ( s ), stdin );
...
Last edited on Apr 5, 2012 at 7:46pm UTC
Apr 5, 2012 at 8:06pm UTC
it continues returning an error...
Last edited on Apr 5, 2012 at 8:07pm UTC
Apr 5, 2012 at 8:12pm UTC
Show your codde and error messages.
Apr 5, 2012 at 8:37pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include "stdafx.h"
#define SkipSpaces( p ) while( isspace( *( p ) ) ) ++( p )
#define ExtractWord( p ) while ( !isspace( *( p ) ) && *( p ) ) ++( p )
int main( void )
{
char s[80];
char *p = s;
puts( "Please enter your sentence" );
fgets( s, sizeof ( s ), stdin );
for (;p<s+80;++p){
s[*p];
SkipSpaces(p);
ExtractWord(p);
}
for (int i = 0 ; i < 80; i++){
printf("%c" , s[i]);
}
puts( "Press any key to continue..." );
getch();
return ( 0 );
}
Unhandled exception at 0x5894de8f (msvcr100d.dll) in Job9.exe: 0xC0000005: Access violation writing location 0xffffffcc.
Last edited on Apr 5, 2012 at 8:42pm UTC
Apr 5, 2012 at 9:03pm UTC
Does the following code work?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include "stdafx.h"
#define SkipSpaces( p ) while( isspace( *( p ) ) ) ++( p )
#define ExtractWord( p ) while ( !isspace( *( p ) ) && *( p ) ) ++( p )
int main( void )
{
char s[80];
char *p = s;
char *q;
char *min_pos = NULL;
int min_len = 0;
puts( "Please enter your sentence" );
fgets( s, sizeof ( s ), stdin );
while ( *p )
{
SkipSpaces( p );
if ( *p )
{
q = p;
ExtractWord( p );
if ( min_pos == NULL || p - q < min_len )
{
min_pos = q;
min_len = p - q;
}
}
}
if ( min_pos != NULL )
{
*( min_pos + min_len ) = '\0' ;
printf( "Minimum word is \"%s\"\n" , min_pos );
}
puts( "Press any key to continue..." );
getch();
return ( 0 );
}
Last edited on Apr 5, 2012 at 9:05pm UTC
Apr 5, 2012 at 9:37pm UTC
What is it ?
s[*p];
*p is some symbol in your string. You use that symbol as an index in your array. For example if *p is equal to 'a' which has code 97 then you reference to memory outside your array.
Last edited on Apr 5, 2012 at 9:42pm UTC