INDAPlus21 / INDAPlus21/eliased-c-task-7
Pass
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Very well done Elias!**
I like your code!
Here are some notes on your code:
#### Cyber-Clara och anmälningslistorna
Instead of using two large buffers, you could make due with one big and one small.
_Your code_:
```c
char namevec[howmanynames*2][42];
char accvec[howmanynames][42];
for(int i=0; i < howmanynames*2; i++) {
scanf("%s", &namevec[i][0]);
}
for(int i=0; i < howmanynames; i++) {
char *concated = strcat(strcat(namevec[i], " "), namevec[i+howmanynames]);
strcpy(accvec[i], concated); //namevec[i];
}
```
_Suggestion_:
```c
char namevec[howmanynames*2][42];
char name[42];
for(int i=0; i < howmanynames; i++) {
scanf("%s", namevec[i][0]);
}
for(int i=0; i < howmanynames; i++) {
scanf("%s", name);
strcpy(namevec[i][0], strcat(strcat(namevec[i], " "), name));
}
```
#### Summera tal
My objection is your use of heap allocation. Stack allocation is only dangerous if a pointer to such data is returned from the procedure in questioned, not if the pointer is used as argument. Yes, some IDE C-extensions will give warnings for non-constant stack allocation sizes, but such are allowed by the ISO C99 standard. The ISO C90 standard however whould, in case of `int numvec[howmanynums];`, produce:
```
sum.c: In function ‘main’:, not dynamic array.
sum.c:16: warning: ISO C90 forbids variable length array ‘howmanynums’
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the existing C implementation for the sections named “Cyber-Clara och anmälningslistorna” and “Summera tal,” using the code and allocation suggestions in this issue as context. Done means the relevant buffer and allocation choices have been assessed and the program still handles both input flows correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- cli
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100