C
C#2y ago
zyn

❔ how to create an array to enter user for super admin

I'm trying to wrap my head around how I would use a string of arrays to let the user enter their username which would then grant them admin privilege's
31 Replies
Jimmacle
Jimmacle2y ago
you mean an array of strings? do you want to have a list of all the names of people with admin privileges?
zyn
zynOP2y ago
yes my bad, an arrary of strings, I want it to be where when you enter a user name itll give the user admin privileges
Jimmacle
Jimmacle2y ago
so is this checking for admin privileges or configuring who has them?
zyn
zynOP2y ago
it will check to see if the user has adm,in privileges and if they do not, will add them to the system,
Jimmacle
Jimmacle2y ago
so it's configuring who has them what kind of application is this? console, winforms, wpf, etc
zyn
zynOP2y ago
im using visual studio for c# language
friedice
friedice2y ago
visual studio is the IDE, what application are you building?
zyn
zynOP2y ago
like what is the purpose of what I'm trying to code?
Jimmacle
Jimmacle2y ago
do you have a GUI?
zyn
zynOP2y ago
i do not
Jimmacle
Jimmacle2y ago
so that means it's a console application
zyn
zynOP2y ago
yes, and I have to run it through visual studio so that when a user enters their username, it'll add it to the super admin privilege's through a array of strings
Jimmacle
Jimmacle2y ago
okay, so how far did you get so far?
zyn
zynOP2y ago
im half way through but I think i did it wrong, I just started using c# so I'm kind of clueless with where i'm going right now
Jimmacle
Jimmacle2y ago
alright, share what you have so far and describe exactly where you're stuck
zyn
zynOP2y ago
include <stdio.h> #include <stdlib.h> #include <string.h> #define NUMSTR 3 #define BUFFSIZE 100 int main(void) { char words[NUMSTR]; char buffer[BUFFSIZE]; size_t i, count = 0, slen; for (i = 0; i < NUMSTR; i++) { printf("Enter Username: "); if (fgets(buffer, BUFFSIZE, stdin) == NULL) { fprintf(stderr, "Error reading string into buffer.\n"); exit(EXIT_FAILURE); } slen = strlen(buffer); if (slen > 0) { if (buffer[slen-1] == '\n') { buffer[slen-1] = '\0'; } else { printf("Exceeded buffer length of %d.\n", BUFFSIZE); exit(EXIT_FAILURE); } } if (!buffer) { printf("Incorrect User.\n"); exit(EXIT_FAILURE); } words[count] = malloc(strlen(buffer)+1); if (!words[count]) { printf("Cannot allocate memory for string.\n"); exit(EXIT_FAILURE); } strcpy(words[count], buffer); count++; }
printf("\nYour strings:\n"); for (i = 0; i < count; i++) { printf("words[%zu] = %s\n", i, words[i]); free(words[i]); words[i] = NULL; } return 0; }
friedice
friedice2y ago
C Hmm
Jimmacle
Jimmacle2y ago
that's not C#... not even C++, that is indeed straight C $c
MODiX
MODiX2y ago
We're partnered with Together C & C++, check them out here: https://discord.gg/vnyVmAE
Jimmacle
Jimmacle2y ago
you probably want to go there
zyn
zynOP2y ago
so I did it all wrong, I see
Jimmacle
Jimmacle2y ago
i mean, not necessarily but if you meant to be writing C# then yes it's a completely different language
zyn
zynOP2y ago
i have to use c# for the frontend
Jimmacle
Jimmacle2y ago
like blazor? or what
zyn
zynOP2y ago
yeah for blazoer blazor*
Jimmacle
Jimmacle2y ago
so how did you manage to get so far into writing C without realizing it wasn't C# thonk
zyn
zynOP2y ago
I thought C and c# shared similar coding structures, so i basically just took a shot in the dark at it thinking it would work
Jimmacle
Jimmacle2y ago
no, they're incompatible (that isn't entirely true but that's out of scope of this project) you should follow a C# tutorial like $helloworld
zyn
zynOP2y ago
ok thank you so much for the help! 😄
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server