Покажи Публикации - iHshar
* Виж публикациите на потр. | Виж темите на потр. | Виж прикачените файлове на потр
Страници: [1]
1  Програмиране / Общ форум / Re: Търся добра книга за C++, която да ме продължи. -: Apr 08, 2015, 12:06
Трябва ми хартиена книга. Да не е някаква адванс или пък бегинър. Нещо средно, което е след структури. и ще ме преведе от С към С++
2  Програмиране / Общ форум / Търся добра книга за C++, която да ме продължи. -: Apr 08, 2015, 11:50
Здраеите приятели. Намирам се на кръстопът. Приключих книгата на Хърб Шилтд - С практически самоучител.
Тя стига до структури и обединения. Сега искам да се прехвърля към c++ и ооп, Разгледах в родните книжарници, но не намерих подходяща книга за това. Тази на Шилтд Ц++ е за по-адванс неща, апък другите книги за ц++ са от бегинър левел, т.е почват от стрингове, ареи и т.н. Трябва ми нещо, което да продължи развитието ми към ц++ със сложност.. след структури и да минава към ооп. Моля препоръчаите ми четиво, на английски, на български, няма значение.
3  Програмиране / Общ форум / Re: Bubble sort на елементи на структура C program -: Mar 26, 2015, 09:53
Благодаря за мненията. Ок, оправих първата грешка, беше от недовиждане.
Идеята ми е да разменя всички данни в структурата, а не само age. По мое мнение трябва да работи и не разбирам грешката:

test1.c:36:11: error: incompatible type for argument 2 of ‘strcpy’
           strcpy(t, item[e-1]);
           ^
In file included from test1.c:2:0:
/usr/include/string.h:129:14: note: expected ‘const char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test1.c:37:11: error: incompatible type for argument 1 of ‘strcpy’
           strcpy(item[e-1], item[e]);
           ^
In file included from test1.c:2:0:
/usr/include/string.h:129:14: note: expected ‘char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test1.c:37:11: error: incompatible type for argument 2 of ‘strcpy’
           strcpy(item[e-1], item[e]);
           ^
In file included from test1.c:2:0:
/usr/include/string.h:129:14: note: expected ‘const char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test1.c:38:11: error: incompatible type for argument 1 of ‘strcpy’
           strcpy(item[e], t);
           ^
In file included from test1.c:2:0:
/usr/include/string.h:129:14: note: expected ‘char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
4  Програмиране / Общ форум / Bubble sort на елементи на структура C program -: Mar 25, 2015, 10:46
Здравейте, исползвам метода на мехуечето за да сортирам имена по азбучен ред. Когато стринговете не са в структура се получава, но когато опитам да ги напраяв във структура със други данни ми дава куп грешки.
Ето сорса:

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


struct students {
  char name[80];
  int age[80];
} item[100];

int main()
{

  char t[100];
  int maxstud, j, e;
  int choice;
  printf("How many students you have?: ");
  scanf("%d", &maxstud);

  for(j=0; j<maxstud; j++){
    printf("Enter Name: ");
    scanf("%s", item[j].name);
    printf("Enter Age ");
    scanf("%d", &item[j].age);
  }

  printf("Sorting: \n");
  printf("1. Sort by name (alhabetical)\n");
  printf("2. Sort by age\n");
  printf("Enter your choicie: ");
  scanf("%d", &choice);

  if(choice==1){
    for(j=1; j<maxstud-1; ++j)
      for(e=maxstud-1; e>=j; --e){
        if(strcmp(item[e-1].name, item[e].name) >0){
          strcpy(t, item[e-1]);
          strcpy(item[e-1], item[e]);
          strcpy(item[e], t);
        }
      }
      for(j=0; j<maxstud; j++)
      printf("Name: %s \t Age: ", item[j].name, item[j].age);
    }

    return 0;
}

Ето и грешките от компилатора:

est.c: In function ‘main’:
test.c:23:5: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int (*)[80]’ [-Wformat=]
     scanf("%d", &item[j].age);
     ^
test.c:36:11: error: incompatible type for argument 2 of ‘strcpy’
           strcpy(t, item[e-1]);
           ^
In file included from test.c:2:0:
/usr/include/string.h:129:14: note: expected ‘const char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test.c:37:11: error: incompatible type for argument 1 of ‘strcpy’
           strcpy(item[e-1], item[e]);
           ^
In file included from test.c:2:0:
/usr/include/string.h:129:14: note: expected ‘char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test.c:37:11: error: incompatible type for argument 2 of ‘strcpy’
           strcpy(item[e-1], item[e]);
           ^
In file included from test.c:2:0:
/usr/include/string.h:129:14: note: expected ‘const char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^
test.c:38:11: error: incompatible type for argument 1 of ‘strcpy’
           strcpy(item[e], t);
           ^
In file included from test.c:2:0:
/usr/include/string.h:129:14: note: expected ‘char * __restrict__’ but argument is of type ‘struct students’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
5  Програмиране / Общ форум / Re: Проблем със gcc компилатора във "С" -: Jan 04, 2015, 17:02
Или да си сканирам стринговете със scanf("%s", str); на този етап ми върши работа
6  Програмиране / Общ форум / Проблем със gcc компилатора във "С" -: Jan 04, 2015, 12:21
Здравеите, ползвам ubuntu 14.04 и съм със GCC компилатор. Програмирам под 'с'. Когато във кога поставя функцията gets(); компилатора ми дава грешка. Ето я и нея: test.c: In function ‘main’:
test.c:8:2: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
  gets(str);
  ^
/tmp/cczj6WBW.o: In function `main':
test.c:(.text+0x2e): warning: the `gets' function is dangerous and should not be used.


Страници: [1]