Anyone good in C ?
Here's the program:
#include <stdio.h>
/* This program removes a string from another string */
void RemoveString(Source, Start, NumChar)
char Source[];
int Start, NumChar;
{
int i = 0, j = 0;
char Test[50];
while ( Source != '\0' )
{
Test = Source;
i++;
}
for ( i = 0; i < NumChar; i++ )
Source[Start+ i] = Test[Start + NumChar+ i];
Source[Start + i] = '\0';
printf ("%s\n", Source);
}
main()
{
RemoveString( "This does not work", 10, 4);
}
Here's how it works, or how it is supposed to work:
The program calls the RemoveString function with three arguments:
1. The string
2. The index in the string where the string that's to be taken out starts.
3. The number of letters that the string has.
In this example 10 refers to 'n' , 4: 4 letters("not "). So at the end, the output of the program should be: "This does work", since the not, plus the space has been taken out.
But I get an execution error at this line:
Source[Start+ i] = Test[Start + NumChar+ i];
And I don't understand why.
What I want to do is to copy the rest of the string (what is after the word to be taken out), over the location of that particular word.
so "Start + i" is the index of the first letter (i being 0 at the start of the loop), in which the letter after the word to be taken out should be copied (Start = 10 + Numchar = 4 + i = 0 = 14: which represents 'w' in the string. So 'w' should be copied where 'n' is, 'o' where 'o' is, 'r' where 't' is, and so on, until 'i' is equal to Numchar.
After that, I copy the NULL character to the end of the string, and display it.
I'd like to know what the FUCK is wrong with that FUCKING line. It seems right to me !!!!!!!!!!!
EDIT: I know this is a bit unreadable but I can't seem to be able to make the tabs in here.
Initially, I wanted it to be Source[Start + i] = ..................I found it..
Here's the program:
#include <stdio.h>
/* This program removes a string from another string */
void RemoveString(Source, Start, NumChar)
char Source[];
int Start, NumChar;
{
int i = 0, j = 0;
char Test[50];
while ( Source != '\0' )
{
Test = Source;
i++;
}
for ( i = 0; i < NumChar; i++ )
Source[Start+ i] = Test[Start + NumChar+ i];
Source[Start + i] = '\0';
printf ("%s\n", Source);
}
main()
{
RemoveString( "This does not work", 10, 4);
}
Here's how it works, or how it is supposed to work:
The program calls the RemoveString function with three arguments:
1. The string
2. The index in the string where the string that's to be taken out starts.
3. The number of letters that the string has.
In this example 10 refers to 'n' , 4: 4 letters("not "). So at the end, the output of the program should be: "This does work", since the not, plus the space has been taken out.
But I get an execution error at this line:
Source[Start+ i] = Test[Start + NumChar+ i];
And I don't understand why.
What I want to do is to copy the rest of the string (what is after the word to be taken out), over the location of that particular word.
so "Start + i" is the index of the first letter (i being 0 at the start of the loop), in which the letter after the word to be taken out should be copied (Start = 10 + Numchar = 4 + i = 0 = 14: which represents 'w' in the string. So 'w' should be copied where 'n' is, 'o' where 'o' is, 'r' where 't' is, and so on, until 'i' is equal to Numchar.
After that, I copy the NULL character to the end of the string, and display it.
I'd like to know what the FUCK is wrong with that FUCKING line. It seems right to me !!!!!!!!!!!
EDIT: I know this is a bit unreadable but I can't seem to be able to make the tabs in here.
Initially, I wanted it to be Source[Start + i] = ..................I found it..