I am trying to make a function that will filter a user input to just the letter and all capitalized. It will get all the letters together but it sometimes also gives me boxes with it. I dont know how to fix it, any help would be appreciated.
Thanks.
void filterinput(char in[], int length, char out[])
{
int i, j=0;
for(i=0; i%26lt;length-1; i++)
{
if(in[i]%26gt;='a' %26amp;%26amp; in[i]%26lt;='z')
{
out[j] = in[i] - 32;
j++;
}
if(in[i]%26gt;='A' %26amp;%26amp; in[i]%26lt;='Z')
{
out[j] = in[i];
j++;
}
}
}
Here is my function call:
filterinput(orig, len, filt);
orig and filt are character arrays with 256 characters
len is a integer that is the length of the string of characters
C Programming?
Are the box type characters coming at the end?
If that is the case, try the following:
Use:
for(i=0; i%26lt;length-1 %26amp;%26amp; in[i] != '\0'; i++)
instead of:
for(i=0; i%26lt;length-1; i++)
in your code
You may also have to terminate your out[] array with a '\0' for printf to work properly.
For this you need to insert the following at the end of your for loop.
out[j] = '\0';
All the best.
primrose
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment