int and char being converted to ascii why??

For some reason when I store a char and an int into my struct it's storing the ascii value into the object. I can test with cout in the function where the input is taken but once i send the char to another function and cout it there it outputs an ascii value for both the char and the int as well as store those ascii in my struct.

my struct:
1
2
3
4
5
6
7
struct pcb{
    string processName;
    char processClass;// a = application, s = system
    int priority;     // -127 to 128
    int state;        // 0 = Running, 1 = Ready, 2 = Blocked, 3 = Suspended Ready, 4 = Suspended Blocked
    int memory;       //memory required
};


Original section of function with input:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void createPCB(queueList*& listName)
{
    string pname;
    char pClass;
    int pPriority;
    bool success = false;

    pcb * tempPCB;

    while (!success)
    {
        cout << "Enter the process name (must be unique):";
        getline(cin, pname);
        cout << "Enter the class (a - application | s - system): ";
        cin >> pClass;
        cout << "Enter the Priority(-127 to 128): ";
        cin >> pPriority;

        tempPCB = setupPCB(pname, pClass, pPriority, listName);


function that is inputting the char and int as ASCII values
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
pcb* setupPCB(string name, int priority, char processClass, queueList*& listName)
{
    pcb * temp = NULL;
    
    //check if a pcb exists
    temp = findPCB(listName, name);

    //Create a new pcb if none exists
    if (temp == NULL)
    {
        temp = allocatePCB();

        temp->processName = name;
        temp->processClass = processClass;
        temp->priority = priority;
        temp->state = 1;
        temp->memory = 1;
    }
    else
    {
        //Name was not unique, return NULL

        temp = NULL;
    }

    return temp;

}
You're mixing up your params:

1
2
3
4
tempPCB = setupPCB(pname, pClass, pPriority, listName); // putting class 2nd, priority 3rd

// but the function takes priority 2nd and class 3rd
pcb* setupPCB(string name, int priority, char processClass, queueList*& listName)



Your compiler really should be giving you a warning about this. Conversion to a lower type (int to char) typically throws a warning... that should have tipped you off. If you're not getting a warning, you might want to tweak your warning level in your compiler settings.
I see. A stupid mistake on my part that I should have seen. Thanks I will check the warning levels in the compiler settings.
Topic archived. No new replies allowed.