Question

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #pragma warning(disable : 4996) // to avoid scanf...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#pragma warning(disable : 4996) // to avoid scanf error, Visual Studio only
#define MAX_DIM 3
#define STUDENTS 5            // total number of students
int scores[STUDENTS];
int *pScores = NULL;

C language

Implement the function that creates and displays the user name of the user. Ask the
user for their first and last name.
The username is the first letter of first name, followed by the last name. For
instance, if the user's name is John Doe, then the username is jdoe.
The user may input upper or lower case characters for first and last name. Make
sure that the username is all UPPER CASE.
Note : When using fgets(), when you press Enter to finish entering the string, the
Enter (\n) character is also added to the string.
Try to remove that character.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

Code as txt:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

const int max = 50;

void createAndDisplayUserName(char fname[], char lname[]) {
   /* This function creates and displays username */
  
   char username[max];
  
   // username is first character of first name
   username[0] = toupper(fname[0]);
   // and followed by last name
   for (int i = 0; lname[i] != '\0'; i++) {
       username[i+1] = toupper(lname[i]);
   }
   printf("Username is %s.\n", username);
}

int main() {
   char fname[max], lname[max];
   printf("Enter first name: ");
   fgets(fname, max, stdin);
   // remove '\n' character
   int fln = strlen(fname);
   fname[fln-1] = '\0';

   printf("Enter last name: ");
   fgets(lname, max, stdin);
   // remove '\n' character
   int lln = strlen(lname);
   lname[lln-1] = '\0';
  
   createAndDisplayUserName(fname, lname);

   return 0;
}

Sample run:

Enter first name: john Enter last name: Doe Username is JDOE.

Note: Ask any doubst in comments and don't forget to rate the answer.

Add a comment
Know the answer?
Add Answer to:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #pragma warning(disable : 4996) // to avoid scanf...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here....

    #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } }    return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...

  • part8.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> /* In part8.c, you will implement a...

    part8.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> /* In part8.c, you will implement a function, called string_token, that * splits a string into a sequence of tokens according to * a specific delimiter character. * * On the first call, the string to be parsed is given in the "str" argument. The "saveptr" * argument is ignored. The function returns "saveptr", which is to be used internally by string_token() in * subsequent calls that parse the same string...

  • ​what's wrong with my code?????? #include <stdio.h> #include <stdlib.h> #include <string.h>                         &

    ​what's wrong with my code?????? #include <stdio.h> #include <stdlib.h> #include <string.h>                            #define MAXBINS 99 #define MAXCORS 26 #define MAXCUS 100 #define MAXPUR 10 /* datatype for a list of orders ----------------- */ typedef struct { int bin_order_number; char bin_order_char; }bin_order; typedef struct { int orderNo; bin_order orderbin; }order; typedef struct { int cusnumber; int n;   /* number of the orders what the txt include */ order oo[MAXPUR+1]; }customer; typedef struct{ int n; /*number of the customers */ customer cc[MAXCUS+1];...

  • devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include...

    devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h>    #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w';    if(argc...

  • Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n...

    Use C++ #include <iostream> #include <stdlib.h> #include <stdio.h> #include <cstring> using namespace std; /I Copy n characters from the source to the destination. 3 void mystrncpy( ???) 25 26 27 28 29 11- 30 Find the first occurrance of char acter c within a string. 32 ??? mystrchr???) 34 35 36 37 38 39 / Find the last occurrance of character c within a string. 40 II 41 ??? mystrrchr ???) 42 43 45 int main() char userInput[ 81]; char...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[],...

    Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[], int *p_top, char value); char pop(char S[], int *p_top); void printCurrentStack(char S[], int *p_top); int validation(char infix[], char S[], int *p_top); char *infix2postfix(char infix[], char postfix[], char S[], int *p_top); int precedence(char symbol); int main() { // int choice; int top1=0; //top for S1 stack int top2=0; //top for S2 stack int *p_top1=&top1; int *p_top2=&top2; char infix[]="(2+3)*(4-3)"; //Stores infix string int n=strlen(infix); //length of...

  • #include <stdio.h> #include string.h     #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE...

    #include <stdio.h> #include string.h     #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE 35.00 #define MV4_PRICE 18.49 #define DISCOUNT        0.05 #define DISC_THRES    10 #define SAME_DAY_DELIVERY =   35.0 #define NEXT_DAY_DELIVERY =   20.0    typedef enum{ WRONG, C17, F25, DN3, GG7, MV4} part     /*--- Function Prototypes ------------*/ part getPartType ( void ); int getquantity ( void ); int getDeliveryOption ( void ); float calcPriceOfParts( part orderedPart, int quantity ); float calcTotalCarges ( float orderPrice, char...

  • Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include...

    Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT