C# Write a program that performs string processing on all strings. char *my_fget
ID: 3707402 • Letter: C
Question
C#
Write a program that performs string processing on all strings.
char *my_fgets (char *s, int n, FILE *stream) — Reads at most one less than the number of characters specified by n, into the array pointed to by s, from the input pointed to by stream. No more characters are read after a newline is encountered or end of file is encountered. The newline if encountered is stored by the array pointed to by s. A null character is appended to the end of string s. If the function is successful in reading characters into s, then s is returned; otherwise a NULL pointer is returned.
int my_fputs (const char *s, FILE *stream) - Writes s to the output specified by stream. If the function is successful, then it returns the number of characters written to the output; otherwise it returns MY_EOF (i.e. for cases where stream does not point any where yet). Make sure you #define MY_EOF as -1.
int my_fgetc (FILE *stream) - Reads the next character from the input pointed to by stream. If the input is at the end of file or a processing error occurs return MY_EOF; otherwise return the integer representation of the character read.
int my_fputc (int c, FILE *stream) - Writes the character c (converted to a character) to the output specified by stream. If the write is successful the ascii value of the character is returned; otherwise MY_EOF is returned.
char *my_gets (char *s) - Reads characters from stdin into the array pointed to by s until a newline is encountered. The newline character is NOT kept at the end of the array pointed to by s. A null character is written to the end of string s. The function returns s.
int my_puts (const char *s) - Writes the string pointed to by s to stdout. The function appends a newline to the output. The function returns the number of characters written to the output.
int my_getchar (void) - Returns the ascii value of the next character read from stdin.
Explanation / Answer
class Program
{
static void Main(string[] args)
{
string s = string.Empty;
s = Console.ReadLine();
int number = 0;
int capitalLetter = 0;
int smallletter = 0;
int space = 0;
int SpecialSymbol = 0;
char[] a = s.ToCharArray();
for (int i = 0; i < a.Length; i++)
{
if (a[i] >= 48 && a[i] <= 58)
{
number += 1;
}
else if (a[i] >= 65 && a[i] <= 90)
{
capitalLetter += 1;
}
else if (a[i] >= 97 && a[i] <= 122)
{
smallletter += 1;
}
else if (a[i] == 32)
{
space += 1;
}
else
{
SpecialSymbol += 1;
}
}
Console.Write("Capital Letter " + capitalLetter);
Console.Write(" small letter " + smallletter);
Console.Write(" number are " + number);
Console.Write(" Total Spaces " + space);
Console.Write(" Total Special Symbol are " + SpecialSymbol);
Console.ReadLine();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.